Site Logo

Negative Numbers

Website

Home | Previous | Next

Negative Numbers

Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
-128
80
-127
81
-126
82
-125
83
-124
84
-123
85
-122
86
-121
87
-120
88
-119
89
-118
8A
-117
8B
-116
8C
-115
8D
-114
8E
-113
8F
-112
90
-111
91
-110
92
-109
93
-108
94
-107
95
-106
96
-105
97
-104
98
-103
99
-102
9A
-101
9B
-100
9C
-099
9D
-098
9E
-097
9F
-096
A0
-095
A1
-094
A2
-093
A3
-092
A4
-091
A5
-090
A6
-089
A7
-088
A8
-087
A9
-086
AA
-085
AB
-084
AC
-083
AD
-082
AE
-081
AF
-080
B0
-079
B1
-078
B2
-077
B3
-076
B4
-075
B5
-074
B6
-073
B7
-072
B8
-071
B9
-070
BA
-069
BB
-068
BC
-067
BD
-066
BE
-065
BF
-064
C0
-063
C1
-062
C2
-061
C3
-060
C4
-059
C5
-058
C6
-057
C7
-056
C8
-055
C9
-054
CA
-053
CB
-052
CC
-051
CD
-050
CE
-049
CF
-048
D0
-047
D1
-046
D2
-045
D3
-044
D4
-043
D5
-042
D6
-041
D7
-040
D8
-039
D9
-038
DA
-037
DB
-036
DC
-035
DD
-034
DE
-033
DF
-032
E0
-031
E1
-030
E2
-029
E3
-028
E4
-027
E5
-026
E6
-025
E7
-024
E8
-023
E9
-022
EA
-021
EB
-020
EC
-019
ED
-018
EE
-017
EF
-016
F0
-015
F1
-014
F2
-013
F3
-012
F4
-011
F5
-010
F6
-009
F7
-008
F8
-007
F9
-006
FA
-005
FB
-004
FC
-003
FD
-002
FE
-001
FF

Positive Numbers

Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
Dec
Hex
+000
00
+001
01
+002
02
+003
03
+004
04
+005
05
+006
06
+007
07
+008
08
+009
09
+010
0A
+011
0B
+012
0C
+013
0D
+014
0E
+015
0F
+016
10
+017
11
+018
12
+019
13
+020
14
+021
15
+022
16
+023
17
+024
18
+025
18
+026
1A
+027
1B
+028
1C
+029
1D
+030
1E
+031
1F
+032
20
+033
21
+034
22
+035
23
+036
24
+037
25
+038
26
+039
27
+040
28
+041
29
+042
2A
+043
2B
+044
2C
+045
2D
+046
2E
+047
2F
+048
30
+049
31
+050
32
+051
33
+052
34
+053
35
+054
36
+055
37
+056
38
+057
39
+058
3A
+059
3B
+060
3C
+061
3D
+062
3E
+063
3F
+064
40
+065
41
+066
42
+067
43
+068
44
+069
45
+070
46
+071
47
+072
48
+073
49
+074
4A
+075
4B
+076
4C
+077
4D
+078
4E
+079
4F
+080
50
+081
51
+082
52
+083
53
+084
54
+085
55
+086
56
+087
57
+088
58
+089
59
+090
5A
+091
5B
+092
5C
+093
5D
+094
5E
+095
5F
+096
60
+097
61
+098
63
+099
63
+100
64
+101
65
+102
66
+103
67
+104
68
+105
69
+106
6A
+107
6B
+108
6C
+109
6D
+110
6E
+111
6F
+112
70
+113
71
+114
72
+115
73
+116
74
+117
75
+118
76
+119
77
+120
78
+121
79
+122
7A
+123
7B
+124
7C
+125
7D
+126
7E
+127
7F

 

Two's complement

The numbers work as follows.

The leftmost bit in an eight bit byte is the sign bit.

    1 0 1 0 1 0 1 0
    ^ 
    ^ The sign bit has a value of -128 decimal or -80 hexadecimal.

The other seven bits are treated as a normal positive number between 0 and 127. This is true whether the overall number is positive or negative. For example to store -1 the binary is

    1 1 1 1 1 1 1 1     - 128d + 127d = -1d
    ^
    ^ -128d 

To store 127 decimal, the binary is

    0 1 1 1 1 1 1 1     0 + 127d = 127d
    ^
    ^ The sign bit is zero.

16 and 32 bit machines also use the leftmost bit as the sign bit. The negative numbers work in exactly the same way but much bigger niumbers can be stored. In a 16 bit machine, the sign bit is worth -32768. In a 32 bit machine, the sign bit is worth -2147483648 (2000 million approximately).

Home | Previous | Next

© C Neil Bauers 2003