Go Down

Topic: Small mistake in Reference (Binary Integer Constants) (Read 2183 times) previous topic - next topic

timograw

Hi, i think i found a small mistake in http://www.arduino.cc/en/Reference/IntegerConstants

binary constants are supposed to look like this
 0bxxxxxxxx
or
 0Bxxxxxxxx

and not as described a simple B.

westfw

The 0b01010101 format is a gcc extension, and not standard C.
The B00101010 format is something provided by "binary.h" in the library include files (a bunch of ordinary preprocessor symbols assigned the appropriate binary values.)
This means that the Bxxxx format is more portable to other compilers.

frank26080115

which other compiler will accept the Bxxxxx format without that huge definition file?
Freelance engineer, consultant, contractor. Graduated from UW in 2013.

westfw

Quote
which other compiler will accept the Bxxxxx format without that huge definition file?

None, and neither does gcc.  But the huge definition file is completely standard and should work with any compiler.

westfw

You can also keep an eye out for this neat set of macros that lets you specify binary constants like:
Code: [Select]
PORTB = B8(1010);
http://bytes.com/topic/c/answers/216333-binary-constant-macros

Go Up