Go Down

Topic: Binary Formatter "B" works only on bytes (Read 2334 times) previous topic - next topic

paulb

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

CosineKitty

As a workaround you can do this:

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

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

jlndrr

#2
May 13, 2007, 06:08 pm Last Edit: May 13, 2007, 08:08 pm by jlndrr Reason: 1
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 !!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy