How to do Byte and Bit banging?

rayzrocket

Member
Licensed User
Longtime User
B4A is great, thanks for developing it!
A microcontroller is sending a 'word' (two bytes) value via bluetooth through asynchstreams into my Driod app (developed using B4A!!), it works very well.
But....
How do I combine the two bytes into one 'Char' ( 2bytes unsigned: 0 to 65535)?

Are functions in B4A for concatinating, removing, shifting bytes and bits available?

-ray
 

rayzrocket

Member
Licensed User
Longtime User
pls help

I have been unable to find a method to concatinate two bytes into a word or char or float...in b4a.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Or if you really insists you could do it with bit-shifting as well ...

ShiftLeft (N As Int, Shift As Int) As Int
 
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
signed to unsigned bytes!!

Thanks for the suggestions, and found out that,
when Asynchstreams receives data on Bluetooth serial connection as bytes in a Buffer(), they are 'signed bytes' which go from
0, 1, 2, 3...127,-127,-126,-125,...-2,-1
therefore simply adding 127 to the value won't fix this.

Erel has a good post that shows the use of converting a signedbyte into unsignedbyte by simple bit banging x0FF,
Bit.And(Value, 0xFF)

Word = HighByte * 256 + LowByte 'works great

I'm not good with simple math, because I'm an "idiot sevant" (more idiot than sevant).

thanks all!
 
Upvote 0
Top