Chapter - 02 - Binary-Numbers
Chapter - 02 - Binary-Numbers
Instructions:
Language of the Computer
Andy D. Pimentel
Adapted from Computer Organization and Design, 5th Edition, Patterson & Hennessy, © 2014, MK
and Toto van Inge / Prof. Mary Jane Irwin
1
But first:
Binary Numbers
2
The Clock and its bases
0 0
Carry Carry
AM/PM x5
base 12 base 60 base 60
4
Base 10 & Base 16
Carry Carry Carry Carry
Base 10
104 103 102 101 100
"
Base 16
164 163 162 161 160
"
Base 2
" 24 23 22 21 20
! 𝑎! # 2! = 𝑎! # 2! + ⋯ + 𝑎# # 2# + 𝑎$ # 2$ + 𝑎% # 2% + 𝑎" # 2"
! "
24 10
23 10
22 10
21 10
20 10
11011b 11100b 11101b 11110b 11111b 00000b 00001b 00010b 00011b 00100b 00101b 00110b 00111b 01000b
27d 28d 29d 30d 31d 00d 01d 02d 03d 04d 05d 06d 07d 08d
6
Unsigned Binary Representation
Hex Binary Decimal
31 30 29 ... 3 2 1 0 bit position
0x00000000 0…0000 0
0x00000001 0…0001 1 231 230 229 ... 23 22 21 20 bit weight
0x00000002 0…0010 2
0x00000003 0…0011 3
0x00000004 0…0100 4
0x00000005 0…0101 5
0x00000006 0…0110 6
0x00000007 0…0111 7
0x00000008 0…1000 8
0x00000009 0…1001 9
…
0xFFFFFFFC 1…1100 1 1 1 ... 1 1 1 1
0xFFFFFFFD 1…1101
0xFFFFFFFE 1…1110
+1
0xFFFFFFFF 1…1111 4294967295
1 0 0 0 ... 0 0 0 0
-1
232 - 1
7
Unsigned Binary Integers
Given an n-bit number
8
Signed Negation
Complement and add 1
◦ Complement means 1 → 0, 0 → 1
x + x = 1111...1112 = -1
x + 1 = -x
Example: negate +2
◦ +2 = 0000 0000 … 00102
◦ –2 = 1111 1111 … 11012 + 12
= 1111 1111 … 11102
9
Review: Signed Binary Representation
2’s-c binary decimal
2s-Complement -23 = 1000 -8
-(23 - 1) = 1001 -7
1010 -6
1011 -5
Complement 1100 -4
all the bits 1011 1101 -3
1110 -2
0101
and add a 1 1111 -1
0000 0
and add a 1 1010 0001 1
10
2s-Complement Signed Integers
Given an n-bit number
Range: –2n – 1 to +2n – 1 – 1
Example
◦ 1111 1111 1111 1111 1111 1111 1111 11002
= –1×231 + 1×230 + … + 1×22 +0×21 +0×20
= –2,147,483,648 + 2,147,483,644 = –410
Using 32 bits
◦ –2,147,483,648 to +2,147,483,647
11