Arduino Forum

Forum 2005-2010 (read only) => Hardware => Bugs & Suggestions => Topic started by: paulb on Feb 14, 2007, 06:13 am

Title: Binary Formatter "B" works only on bytes
Post by: paulb on Feb 14, 2007, 06:13 am
I was trying to format some 16 bit constants in binary format and noticed that the handy binary formatter "B" seems to work only on bytes and not ints (16 bits).

Paul Badger
Title: Re: Binary Formatter "B" works only on bytes
Post by: CosineKitty on Feb 14, 2007, 05:25 pm
As a workaround you can do this:

int x = (B11111111 << 8) | B00000000;

This will get you the same thing as if "B1111111100000000" existed.
Title: Re: Binary Formatter "B" works only on bytes
Post by: jlndrr on May 13, 2007, 06:08 pm
it seems that these formaters are just defined constant :

#define B11111110 254
#define B11111111 255

in binary.h

so you could also define your own set, I suppose, for a whole 16bit integer. Don't forget to add some zeros, like here :

#define B1000 8
#define B01000 8
#define B001000 8
#define B0001000 8
#define B00001000 8

That would be a lot of constants !!