B4J Question Bit manipulation

saunwin

Active Member
Licensed User
Longtime User
Morning all,

Can anyone help me with this ?
I'm trying to calculate a received (8 bit bytes) packet checksum.
Below is some code that takes the 2nd byte of the packet (which is the length packet).
My protocol disallows bit 7 to be hi (that means something else). so the received checksum is a 6 bit sum of the received bytes.
The AND-ing of checksum isn't working, anyone know why ? - thanks in advance


x=Buffer(1) 'packet length
Dim y As Int = 0 'dim & zero temp variables
Dim checksum as long = 0
For y = 1 To x-1 'Range is byte 1 to packet length-1 (last byte is CSum)
checksum=checksum+(Buffer(y)) 'Add up bytes
Next

Bit.And(checksum,127) 'Strip bits 7 upwards !!!!!!!!!!! - not working

strtemp=Bit.ToHexString(checksum) 'make checksum displayable as a hex number

monitor.Text=monitor.Text & "Checksum - " & strtemp & CRLF 'display checksum - & value
 

saunwin

Active Member
Licensed User
Longtime User
OK Figured it out - I'm being a twonk (again)
the line should be - checksum=Bit.And(checksum,127)
 
Upvote 0
Top