in Programming
210 views
1 vote
1 vote

Suppose we have a 32-bit memory and we have to represent

unsigned int a = -5

What will the memory representation look like?

000000…….1011

or 

111…..1011

in Programming
by
210 views

2 Comments

@tusharhigh 

Answer:-- 111…..1011

Explaination: It does not matter wheater we are storing negative integer or positive integer it alway’s follows 2’s complement system .In case of positive value (+5) it directly stores it’s value in its binary format ie: 00 ….0000101 But in case of negative integer (-5) it stores in 2’complement form (111….101).

The role of datatype signed or unsigned comes into the picture when we are trying to access it.if we are using unsigned int value which is stored in memory will directly get converted in decimal format but in case of signed datatype value first converted in normal form and then it used.

 

 

1
1
Thanks man, great explanation
0
0

1 Answer

1 vote
1 vote
Best answer

it will be like 1111...1011

you can check it yourself, just run this-

unsigned int i = -5;

printf(“%x”,i);

or

https://onlinegdb.com/XC_KvJWdjG

selected by

Related questions