Saturday, 28 September 2013

range of size of signed int

range of size of signed int

i was thinking about size of int(signed and unsigned). The size of
unsigned integer is very obvious to calculate but when it came to signed i
got confused.. like if int is of 2 bytes and 15th byte is for sign then
its size is 32767 thats understandable .. but when i tried to calculate
the -ve minimum i did this 1 1111111111111..(16 ones). ignoring the signed
bit(16th) the value was still 32767 so i got range +32767 to -32767(and
thats not the right range) . or maybe this is not the right way to
calculate the range because compiler will take it as -1.
so how +32767 to -32768 is calculated ??

No comments:

Post a Comment