A Scilab game for learning binary-hex conversion

It displays a 4-bit binary number and you should click its hex representation.

binhex1

If you got it right, it will congratulate you.

binhex2

If you are wrong, it will sigh and let you try again or choose another number.

binhex3

The numbers are updated randomly.

This is the code in Scilab:


clear,clc;

buttons = [];
for i = 0:1:15
    buttons = [buttons dec2hex(i)];
end

r_previous = -1;

while (%t)
    r1 = grand(1,1,"uin",0,15);
    while r1 == r_previous
        r1 = grand(1,1,"uin",0,15);
    end

    msg=dec2bin(r1,4);
    r2 = messagebox(msg,'','question',buttons,'modal')-1;
    if r2 < 0 then
        abort
    end

    while (r1 <> r2)
        wrong = 'Wrong! '+msg+' is not ' + dec2hex(r2);
        nxt = messagebox(wrong,'Ohh...','error',...
        ['Try again','Another number','Finish'],'modal')

        if nxt == 1 then
            r2 = messagebox(msg,'','question',...
            buttons,'modal')-1;
            if r2 < 0 then
                abort
            end
        elseif nxt == 2 then
            break
        else
            abort
        end
    end

    if r1==r2 then
        good = 'Good! '+msg+' is '+dec2hex(r2);
        nxt = messagebox(good,'Wow...','',...
        ['Next number','Finish'],'modal')
        if nxt<>1 then
            abort
        end
    end

    r_previous = r1;
end
Advertisements
Published in: on 14/03/2015 at 14:56  Comments (1)  

The URI to TrackBack this entry is: https://burubaxair.wordpress.com/2015/03/14/a-scilab-game-for-learning-binary-hex-conversion/trackback/

RSS feed for comments on this post.

One CommentLeave a comment

  1. Great! I’ve finally found someone that likes Scilab as I do.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: