Go Down

Topic: Base prefix notation (Read 2 times) previous topic - next topic


A 0 (zero) on the front.

Code: [Select]

unsigned char v = 0274;
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10


May 02, 2013, 09:48 pm Last Edit: May 02, 2013, 09:53 pm by AWOL Reason: 1
So... what is octal notation?
But octal notation (leading zero)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


0b is native to the compiler, much like 0x for hex, but it tends to be compiler specific whether that notation is actually supported and I don't believe it is part of the official c standard (gcc I believe does support it, which is the basis for many compilers). All of the Bnnn values are actually defined in a header file (binary.h in your Arduino core library folder). I imagine these were included for maximum compatibility between compilers (or maybe compatibility between programmers). It doesn't really matter which you use, as long as you have a compatible compiler or the right includes.
In terms of octal, C has a pretty stupid/confusing notation:
Code: [Select]
int x=035; <-- x is decimal 29!!!
It's particularly annoying as if you use 0's to try and align your numbers you get a nasty surprise e.g:
Code: [Select]
int c1=134;
int c2=120;
int c3=076; <--- This is troublesome
int c4=098; <--- Ahhhh!!!!!! (actually throws a compiler error!)
int c5=111;

EDIT: LOL, took a bit long typing that out  :P


May 02, 2013, 09:52 pm Last Edit: May 02, 2013, 09:56 pm by Sembazuru Reason: 1

0bnnnnnnnn is C/C++

Bnnnnnnnn is a set of #defines in hardware/arduino/cores/arduino/binary.h:
Code: [Select]

#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1

If you want to be "proper", use 0bnnnnnnnn.

So (as AWOL says) the Arduino "nicety" is actually a kludge that one should probably avoid if one wants to develop good habits to use outside of ArduinoLand(tm). I'll keep my habit of converting "B" to "0b" when cleaning up examples that I'm learning from...


And base 5 is common in counting.  I, II, III, IIII, IIII

Thinking back on it, that is probably where I got it from.

Edit: corrected quote tags... One of the few times I forget to preview my post, and I put a "/" in the wrong place...


So... what is octal notation?
But octal notation (leading zero)

D'oh! I should really read completely. All that slobber on my foot makes walking slippery. ;)

Go Up