Pages: [1]   Go Down
Author Topic: Small mistake in Reference (Binary Integer Constants)  (Read 1778 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Freelance engineer, consultant, contractor. Graduated from UW in 2013.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: