I would have expected to see 16 1's in a row to represent a -1 in an int data type. What printed was 32 1's in a row. This is what gets printed with -2.
jerseyguy1996:
I would have expected to see 16 1's in a row to represent a -1 in an int data type. What printed was 32 1's in a row. This is what gets printed with -2.
a = 11111111111111111111111111111110
This is on an Arduino mega2560
It does not matter what size the data is the 2's complement is always the positve + 1
in 8,16 ,24 , 32 wtc., its just the format - 1 is alway a string if 1's
Useually the hex format ids used
1 in 8 buts = FF
-1 in 16 bits = FFFF
-1 in 24 bits = FFFFFF
-1 in 32 biss = FFFFFFFF
Any other size will be exntened to pacxk FF into the upper order.
.print(int) just calls .print(long). This causes a sign extension to 32 bits which is a problem in BIN and HEX formats. If you cast the value to 'unsigned' it will call .print(unsigned) which will call .print(unsigned long) and therefore no sign extension.