ROBOTC.net forums
http://robotc.net/forums/

Declaring Binary Literals
http://robotc.net/forums/viewtopic.php?f=1&t=7122
Page 1 of 1

Author:  Ernest3.14 [ Tue Oct 29, 2013 7:53 pm ]
Post subject:  Declaring Binary Literals

I don't have access to RobotC right now. I'd like to know whether RobotC supports declaring binary literals like
Code:
byte x = 0b01101001;

According to Stack Overflow, GCC supports this.

Author:  MHTS [ Tue Oct 29, 2013 8:36 pm ]
Post subject:  Re: Declaring Binary Literals

Yep, this works.
Code:
task main()
{
    int data = 0b01101001;
    nxtDisplayTextLine(0, "d=%x", data);
    while (true)
    {
        wait1Msec(100);
    }
}

It gives you "d=69".

Author:  mattallen37 [ Tue Oct 29, 2013 9:25 pm ]
Post subject:  Re: Declaring Binary Literals

Which is correct. However, the format of that looks wrong. It should be noted that 0b01101001 = 0x69 (hex 69, not dec 69) = 105 (decimal).

Whenever I display hex values, just to be clear, I like to precede them with 0x, e.g.
Code:
nxtDisplayTextLine(0, "d=0x%x", data);
which should print "d=0x69".

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/