how to take complement of an 8 bit number?

Hi all

i have a program in which i need to take complements of 8 bit numbers
so if byte1 = 1 then ~byte1 = 0

But the problem is byte1 = 00000001
so when i do ~byte1 i get 11111110 which is essentially -2

Can anyone please tell me how exatcly i can negate 8bit number properly?

Thanks a lot
-Unnati
In two's complement arithmetic, -x=~x+1.
Really, you should have noticed that all your results were off by one.
Topic archived. No new replies allowed.