EDN Admin
Well-known member
Hi I know that
unsigned char is used to store the values from 0 to 255
signed char is used to store the values from -127 to 127
However what I found out is that memory representation of both of those types is the same.
i.e. if I write the following code and see the memory window
<span style="white-spacere unsigned char unsigne[10];<br/>
<span style="white-spacere unsigne[0] = 0;<br/>
<span style="white-spacere unsigne[1] = 1;<br/>
<span style="white-spacere unsigne[2] = -1;<br/>
<span style="white-spacere unsigne[3] = 2;<br/>
<span style="white-spacere unsigne[4] = -2;<br/>
<br/>
<span style="white-spacere signed char signe[10];<br/>
<span style="white-spacere signe[0] = 0;<br/>
<span style="white-spacere signe[1] = 1;<br/>
<span style="white-spacere signe[2] = -1;<br/>
<span style="white-spacere signe[3] = 2;<br/>
<span style="white-spacere signe[4] = -2;
then the memory of both of these pointers contain
00 01 ff 02 fe
I was thinking the memory of signed char would like, if the MSB is the sign bit.
00 01 81 02 82
meaning -1 = 0x81 = 1000 0001
meaning -2 = 0x81 = 1000 0002
View the full article
unsigned char is used to store the values from 0 to 255
signed char is used to store the values from -127 to 127
However what I found out is that memory representation of both of those types is the same.
i.e. if I write the following code and see the memory window
<span style="white-spacere unsigned char unsigne[10];<br/>
<span style="white-spacere unsigne[0] = 0;<br/>
<span style="white-spacere unsigne[1] = 1;<br/>
<span style="white-spacere unsigne[2] = -1;<br/>
<span style="white-spacere unsigne[3] = 2;<br/>
<span style="white-spacere unsigne[4] = -2;<br/>
<br/>
<span style="white-spacere signed char signe[10];<br/>
<span style="white-spacere signe[0] = 0;<br/>
<span style="white-spacere signe[1] = 1;<br/>
<span style="white-spacere signe[2] = -1;<br/>
<span style="white-spacere signe[3] = 2;<br/>
<span style="white-spacere signe[4] = -2;
then the memory of both of these pointers contain
00 01 ff 02 fe
I was thinking the memory of signed char would like, if the MSB is the sign bit.
00 01 81 02 82
meaning -1 = 0x81 = 1000 0001
meaning -2 = 0x81 = 1000 0002
View the full article