Go Down

Topic: bit shifting (Read 975 times) previous topic - next topic

tobyb121

Just like that, but your array definition is all wrong:
'B0001' is not the same as B0001, B0001 is an number type, 'B0001' is an ASCII char type and will give the value 'B', decimal 66 (he other characters are ignored)

TanHadron

Plus, you need parentheses.  << has pretty low precedence.

Code: [Select]

byte testb = (numbers[3] << 4) | numbers[5];

carbondudeoxide

ok i have tried these and if the 8th bit (thats what i belive it is) if the upper most bit (left hand side when writing it) is 0 then it is ommitted but i need to send it as an 8 bit for the i2c i have running so i need it to have 8 bits and not emmit them. how can i ensure it can be used with all 8?

tobyb121


ok i have tried these and if the 8th bit (thats what i belive it is) if the upper most bit (left hand side when writing it) is 0 then it is ommitted but i need to send it as an 8 bit for the i2c i have running so i need it to have 8 bits and not emmit them. how can i ensure it can be used with all 8?

What?!? Maybe read that one back... ;)

carbondudeoxide

basically once i have done the bit shifting if i get a 8-bit binary with a 0 as the last bit (mot left bit one in blue)  01001010 instead of it remaining on the end it is ommited so the binary is displayed as 1001010 instead of 01001010 because i am using this 8-bit binary for an i2c project i need it to have all 8 bits in it. so what i am looking to do is force it to be an 8 bit regardless of it having a 0 on the end


Go Up