Signed integer representeton in memory
For char range -128 to +127;
MSB is used for sign representation, 2 complement is used to represent -ve val
for any -ve value take 2s complement to convert it to hex form. and to return to its original decimal value also do 2s complement.
for example -30 in hex will be 30 = 0x1E => 2s complement =
~0x1E + 1 = 0xE2
To get a -ve decimal value 0xE2 's 2s complement = 1E =30;
Note: 2s complement is used for negative integers (negation of positive int)
Note:char a= 0x80 (== -128); now a<<1 gives -256 (though it's out of range)
Ref:
http://en.wikipedia.org/wiki/Signed_number_representations
http://www.hoomanb.com/cs/yorku/2021/data_representation.pdf
http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/NumSys.html
MSB is used for sign representation, 2 complement is used to represent -ve val
for any -ve value take 2s complement to convert it to hex form. and to return to its original decimal value also do 2s complement.
for example -30 in hex will be 30 = 0x1E => 2s complement =
~0x1E + 1 = 0xE2
To get a -ve decimal value 0xE2 's 2s complement = 1E =30;
Note: 2s complement is used for negative integers (negation of positive int)
Note:char a= 0x80 (== -128); now a<<1 gives -256 (though it's out of range)
Ref:
http://en.wikipedia.org/wiki/Signed_number_representations
http://www.hoomanb.com/cs/yorku/2021/data_representation.pdf
http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/NumSys.html
Comments