Options

# Check Sum Question - for you math people

Posts: 279
Hey All - I have a Hitachi LCOS video wall cube that says it's check sum is a "twos complement" check sum. Looking Two's compliment up on Wikipedia I find that it is a inversion of the bit in a byte plus one. So I am thinking that I can calculate the checksum by doing this:

sum (addition of the Bytes in question)

CheckSum = !Sum + 1

Will that work ? or do I have to go into the bits in the byte and invert each one? before I add one.

Anybody got any suggestions?

• Options
Posts: 4,584
JohnMichnr wrote:
Hey All - I have a Hitachi LCOS video wall cube that says it's check sum is a "twos complement" check sum. Looking Two's compliment up on Wikipedia I find that it is a inversion of the bit in a byte plus one. So I am thinking that I can calculate the checksum by doing this:

sum (addition of the Bytes in question)

CheckSum = !Sum + 1

Will that work ? or do I have to go into the bits in the byte and invert each one? before I add one.

Anybody got any suggestions?

!Sum will make Sum = 1 if it's currently 0, otherwise it will make it 0. So, no matter what's it's value, you are going to wind up with 0 or 1. You need to do a bitwise operation.
• Options
Posts: 279
Yeah now that I go back and re-read the exact defintion of Not, I gues all it does is produce a true/false result.
So it is back to the bitwise not on each bit.
• Options
Posts: 949
CheckSum = ~Sum + 1 is what you're looking for, I believe.
• Options
Posts: 279
Yeah - that is what I am going to try - the other thing that works in teh Windows calculator is taking sum and subtracting it from 0. Cause the twos compliment is just the inverse of the number (negative. I think I'll try both and see what happens.
• Options
Posts: 861
isnt it BNOT? binary not?

edit:
damnit... BNOT == ~ :P
• Options
Posts: 279
I was asked to post the description of the command protocol for this issue. I am going to try to do this.

I don't know how to do the little quote boxes

FORMAT of COMMANDS TO THE PROJECTOR
(A) When individually specifying a projector
STX + BC + CMD + PARA + CS + SN
STX - Start command (fixed to 02H) 1 Byte
BC - Byte count from CMD to the last byte of PARA 1 Byte
CMD - Command code 1 Byte
PARA* Parameter Variable
CS - Value when the sum of the lower 8 bits from BC to CS is 0. Two?s complement. 1 Byte
SN - Projector No.. FFH corresponds to all projectors. 1 Byte

Obviously the area I am looking at is the CS. And I think the BNOT (~) is the way to go about it. I'll be trying that this morning with some strings.
• Options
Posts: 727
Make "count" or somesuch equal to the sum of all the bytes from BC to the last PARA byte. BAND it with \$FF to make sure it's 255 or less. Then...

CS = 256 - count.

- Chip