Pages: [1]   Go Down
Author Topic: Binary Formatter "B" works only on bytes  (Read 1399 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 267
dinosaur cork
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Florida, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 146
meow!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As a workaround you can do this:

int x = (B11111111 << smiley-cool | B00000000;

This will get you the same thing as if "B1111111100000000" existed.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 !!
« Last Edit: May 13, 2007, 01:08:56 pm by jlndrr » Logged

Pages: [1]   Go Up
Jump to: