0% found this document useful (0 votes)
29 views10 pages

Chapter - 02 - Binary-Numbers

Uploaded by

oxagys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Chapter - 02 - Binary-Numbers

Uploaded by

oxagys
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 2

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
"

! 𝑎! # 10! = 𝑎! # 10! + ⋯ + 𝑎# # 10# + 𝑎$ # 10$ + 𝑎% # 10% + 𝑎" # 10"


! "

! 𝑎! # 10! = 𝑎& # 10& + 𝑎# # 10# + 𝑎$ # 10$ + 𝑎% # 10% + 𝑎" # 10"


&
= 5 # 10& + 3 # 10# + 6 # 10$ + 5 # 10% + 8 # 10" = 53658'

Carry Carry Carry Carry

Base 16
164 163 162 161 160
"

! 𝑎! # 16! = 𝑎! # 16! + ⋯ + 𝑎# # 16# + 𝑎$ # 16$ + 𝑎% # 16% + 𝑎" # 16"


"
!
! 𝑎! # 16! = 𝑎& # 16& + 𝑎# # 16# + 𝑎$ # 16$ + 𝑎% # 16% + 𝑎" # 16"
&
= 𝐴 # 16& + 𝐹 # 16# + 0 # 16$ + 4 # 16% + 𝐴 # 16" = 𝐴𝐹04𝐴 ( = 716874'
5
Base 2 or Binary counter
Carry Carry Carry Carry

Base 2
" 24 23 22 21 20
! 𝑎! # 2! = 𝑎! # 2! + ⋯ + 𝑎# # 2# + 𝑎$ # 2$ + 𝑎% # 2% + 𝑎" # 2"
! "

! 𝑎! # 2! = 𝑎& # 2& + 𝑎# # 2# + 𝑎$ # 2$ + 𝑎% # 2% + 𝑎" # 2"


&
= 1 # 16 + 1 # 8 + 0 # 4 + 1 # 2 + 1 # 1 = 11011) = 27'

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

1 cycle = 1 clock tick

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

x = x n-1 2n-1 + x n-2 2n-2 + ! + x1 21 + x 0 20


— Range: 0 to +2n – 1
— Example
◦ 0000 0000 0000 0000 0000 0000 0000 10112
= 0 + … + 1×23 + 0×22 +1×21 +1×20
= 0 + … + 8 + 0 + 2 + 1 = 1110
— Using 32 bits
◦ 0 to +4,294,967,295

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

0110 complement 0010 2


all the bits 0011 3
0100 4
0101 5
0110 6
23 - 1 = 0111 7

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

You might also like