Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

negative integers in binary

 5 (decimal) in binary  00000101
-5 (two's complement) in binary 11111011

but 11111011 is also 251 (decimal)!

How does computer discern one from another?? How does it know whether it's -5 or 251??

it's THE SAME 11111011

Thanks in advance!!

like image 275
DrStrangeLove Avatar asked Mar 11 '26 12:03

DrStrangeLove


1 Answers

Signed bytes have a maximum of 127.

Unsigned bytes cannot be negative.

The compiler knows whether the variable holding that value is of signed or unsigend type, and treats it appropriately.

like image 141
SLaks Avatar answered Mar 13 '26 09:03

SLaks