Loading...
Pages: [1]   Go Down
Author Topic: Small mistake in Reference (Binary Integer Constants)  (Read 1327 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
Faraday Member
**
Karma: 80
Posts: 5513
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: 592
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I'm an electrical engineering student. I designed the USnooBie (V-USB dev kit) which is sold at Seeed Studio

SF Bay Area (USA)
Offline Offline
Faraday Member
**
Karma: 80
Posts: 5513
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
Faraday Member
**
Karma: 80
Posts: 5513
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
Print
 
Jump to: