When bytes, wydes, tetras and octas
represent numbers, they can be signed or
unsigned. In the last case the most significant bit stores
the sign of the number: 0 codes plus and 1 - minus.
Negative numbers are stored in memory in a special way called
complement code. To get this code for negative integer
do the following:
- in absolute value of the binary number change every digit to the
opposite: 0 to 1 and 1 to 0
- add 1 to the result
Such manner of coding provides the easement of arithmetic operations
inside a computer.
Example
Let's convert -127 into complement code:
12710 = | 0111 11112 |
invert: | 1000 0000 |
add 1: | 1000 00012 |
= 8116 |
The coding of several characteristic numbers is shown in the table below.
contents of byte (hex) |
00 | 01 | ... |
7F | 80 | 81 | ... |
FE | FF |
---|
unsigned number (decimal) |
0 | 1 | ... |
127 | 128 | 129 | ... |
254 | 255 |
signed number (decimal) |
0 | 1 | ... |
127 | -128 | -127 | ... |
-2 | -1 |
You can see that an unsigned byte is a number between
0 and 28 - 1 = 255 inclusive.
A signed integer lies between -128 and +127 inclusive.
Similar situation takes place for wydes, tetras and octas.
unit | size | minimum / maximum |
---|
| (bits) |
unsigned |
signed |
byte |
8 | 0 | 28 - 1 = 255 |
-128 | 127 |
wyde |
16 | 0 | 216 - 1 = 65 535 |
-32 768 | 32 767 |
tetra |
32 | 0 | 232 - 1 = 4,294,967,295 |
-2,147,483,648 | 2,147,483,647 |
octa |
64 | 0 | 264 - 1 = 18,446,744,073,709,551,615 |
-9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
Related topics:
"MMIX basics" page
|