How does a computer recognize an integer, signed or unsigned?

There are two additions to simplify the computer calculating two digits. But how does a computer distinguish an integer - an integer or unsigned integer? It is only 0 and 1 in memory.

For exmaple, it 1111 1111can represent 255 in computer memory, but it can also represent -1.

+5
source share
2 answers

Signed and unsigned use the same data, but different instructions.

. 255 -1 - . , . , (, IDIV), (, DIV). , , , .

+10

. :

d b . 8- .

-1d + 1d = 1111 1111b + 1b = 1 0000 0000b

(yep, 8 0 a 1 8- ), 0.

-2d + 1d = 1111 1110b + 1b = 1111 1111b = -1d

-1d + 2d = 1111 1111b + 10b = 1 0000 0001b (this overflows) = 1b = 1d

-1d + -1d = 1111 1111b + 1111 1111b = 1 1111 1110b (this overflows) = 1111 1110b = -2d

( ):

255d + 1d = 1111 1111b + 1b = 1 0000 0000b (this overflows) = 0d

254d + 1d = 1111 1110b + 1b = 1111 1111b = 255d

255d + 2d = 1111 1111b + 10b = 1 0000 0001b (this overflows) = 1b = 1d

255d + 255d = 1111 1111b + 1111 1111b = 1 1111 1110b (this overflows) = 1111 1110b = 2d

, , , : -)

+2

All Articles