equivalent to unbinary() in processing?
hi there
for shifting out data leds need convert individual settings stored in boolean/integer/char (1 = on, 0 = off)
from binary decimal. example:
led1: on 1
led2: on 1
led3: off 0
led4: on 1
settings: 1101
decimal value: 13
in processing, can done unbinary() function.
but how in arduino?
thanks help!
yves
for shifting out data leds need convert individual settings stored in boolean/integer/char (1 = on, 0 = off)
from binary decimal. example:
led1: on 1
led2: on 1
led3: off 0
led4: on 1
settings: 1101
decimal value: 13
in processing, can done unbinary() function.
but how in arduino?
thanks help!
yves
code: [select]
byte ledvalues;
boolean led1;
boolean led2;
boolean led3;
boolean led4;
ledvalues = 13;
led1 = ((ledvalues & (1 << 3)) != 0);
led2 = ((ledvalues & (1 << 2)) != 0);
led3 = ((ledvalues & (1 << 1)) != 0);
led4 = ((ledvalues & (1 << 0)) != 0);
the "!= 0" part not necessary makes clear you're trying accomplish. the "<< 3" part can variable instead of constant (like "<< i").
- brian
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > equivalent to unbinary() in processing?
arduino
Comments
Post a Comment