SlideShare a Scribd company logo
ECE2030
Introduction to Computer Engineering
Lecture 2: Number System
Prof. Hsien-Hsin Sean LeeProf. Hsien-Hsin Sean Lee
School of Electrical and Computer EngineeringSchool of Electrical and Computer Engineering
Georgia TechGeorgia Tech
Decimal Number Representation
• Example: 90134 (base-10, used by Homo Sapien)
= 90000 + 0 + 100 + 30 + 4
= 9*104
+ 0*103
+ 1*102
+ 3*101
+ 4*100
• How did we get it?
901349013410
9013901310 44
90190110 33
909010 11
99 00
Generic Number Representation
• 90134
= 9*104
+ 0*103
+ 1*102
+ 3*101
+ 4*100
• A4A3A2A1A0 for base-10 (or radix-10)
= A4*104
+ A3*103
+A2*102
+A1*101
+A0*100
(A is coefficient; b is base)
• Generalize for a given number NN w/ base-bb
NN = An-1An-2 …A1A0
NN = An-1*bn-1
+ An-2*bn-2
+ … +A2*b2
+A0*b0
**Note that A < b**Note that A < b
Counting numbers with base-bb
00
11
22
33
44
55
66
77
88
99
1010
1111
1212
1313
1414
1515
1616
1717
1818
1919
Base-10
9090
9191
9292
9393
9494
9595
9696
9797
9898
9999
…..
100100
101101
102102
103103
104104
105105
106106
107107
108108
109109
How about Base-8
00
11
22
33
44
55
66
77
1010
1111
1212
1313
1414
1515
1616
1717
2020
2121
2222
2323
2424
2525
2626
2727
7070
7171
7272
7373
7474
7575
7676
7777
…..
100100
101101
102102
103103
104104
105105
106106
107107
2020
2121
2222
2323
2424
2525
2626
2727
2828
2929
How about base-22
00
11
1010
1111
100100
101101
110110
111111
10001000
10011001
10101010
10111011
11001100
11011101
11101110
11111111
How about base-22
00
11
1010
1111
100100
101101
110110
111111
10001000
10011001
10101010
10111011
11001100
11011101
11101110
11111111
How about base-22
00 = 0= 0
11 = 1= 1
1010 = 2= 2
1111 = 3= 3
100100 = 4= 4
101101 = 5= 5
110110 = 6= 6
111111 = 7= 7
10001000 = 8= 8
10011001 = 9= 9
10101010 = 10= 10
10111011 = 11= 11
11001100 = 12= 12
11011101 = 13= 13
11101110 = 14= 14
11111111 = 15= 15
BinaryBinary == DecimalDecimal
Derive Numbers in Base-2
• Decimal (base-10)
– (25)10
• Binary (base-2)
– (11001)2
• Exercise
25252
12122 11
662 00
332 00
11 11
Base-2
• Decimal (base-10)
– (982)10
• Binary (base-2)
– (1111010110)2
• Exercise
0
Base 8
• Decimal (base-10)
– (982)10
• Octal (base-8)
– (1726)8
• Exercise
1
Base 16
• Decimal (base-10)
– (982)10
• Hexadecimal (base-16)
• Hey, what do we do when we
count to 10??
• 0
• 1
• 2
• 3
• 4
• 5
• 6
• 7
• 8
• 9
• 10
• 11
• 12
• 13
• 14
• 15
00
11
22
33
44
55
66
77
88
99
aa
bb
cc
dd
ee
ff
2
Base 16
• (982)10= (3d6)16
• (3d6)16 can be written as (0011 1101 0110)2
• We use Base-16 (or Hex) a lot in computer
world
– Ex: A 32-bit address can be written as
0xfe8a7d200xfe8a7d20 ((0x0x is an abbreviation of Hex))
– Or in binary formOr in binary form
1111_1110_1000_1010_0111_1101_0010_00001111_1110_1000_1010_0111_1101_0010_0000
3
Number Examples with Different Bases
• Decimal (base-10)
– (982)10
• Binary (base-2)
– (01111010110)2
• Octal (base-8)
– (1726)8
• Hexadecimal (base-16)
– (3d6)16
• Others examples:
– base-9 = (1321)9
– base-11 = (813)11
– base-17 = (36d)17
4
Convert between different bases
• Convert a number base-x to base-y, e.g. (0100111)2 to (?)6
– First, convert from base-x to base-10 if x ≠ 10
– Then convert from base-10 to base-y
0100111 = 0∗26 + 1∗25 + 0∗24
+ 0∗23
+ 1∗22
+ 1∗21
+ 1∗20
= 39
39396
666 33
11 00
∴ (0100111)2 = (103)6
Base-b Addition
6
Negative Number Representation
• Options
– Sign-magnitude
– One’s Complement
– Two’s Complement (we use this in this course)
7
Sign-magnitude
• Use the most significant bit (MSB)
to indicate the sign
– 00: positive, 11: negative
• Problem
– Representing zeros?
– Do not work in computation
• We will NOT use it in this course !
+0 000
+1 001
+2 010
+3 011
-3 111
-2 110
-1 101
0 100
8
One’s Complement
• Complement (flip) each bit in a
binary number
• Problem
– Representing zeros?
– Do not always work in computation
• Ex: 111 + 001 = 000 → Incorrect !
• We will NOT use it in this course !
+0 000
+1 001
+2 010
+3 011
-3 100
-2 101
-1 110
0 111
9
Two’s Complement
• ComplementComplement (flip) each bit in a
binary number and adding 1adding 1, with
overflow ignored
• Work in computation perfectly
• We will use it in this course !
011
100
One’s complement
3
101
Add 1
-3
010
One’s complement
101-3
011
Add 1
3
0
Two’s Complement
• ComplementComplement (flip) each bit in a
binary number and adding 1adding 1, with
overflow ignored
• Work in computation perfectly
• We will use it in this course !
0 000
+1 001
-1 111
+2 010
-2 110
+3 011
-3 101
?? 100
100
011
One’s complement
100
Add 1
The same 100 represents
both 4 and -4
which is no good
1
Two’s Complement
• ComplementComplement (flip) each bit in a
binary number and adding 1adding 1, with
overflow ignored
• Work in computation perfectly
• We will use it in this course !
0 000
+1 001
-1 1111
+2 010
-2 1110
+3 011
-3 1101
--4 1100
100
011
One’s complement
100
Add 1
MSB = 1 for negative
Number, thus 100
represents -4
2
Range of Numbers
• An N-bit number
– Unsigned: 0 .. (2
N
-1)
– Signed: -2
N-1
.. (2
N-1
-1)
• Example: 4-bit
1110 (-8) 0111 (7)
Signed numbers
0000 (0) 1111 (15)Unsigned numbers
3
Binary Computation
010001 (17=16+1)
001011 (11=8+2+1)
---------------
011100 (28=16+8+4)
Unsigned arithmetic
010001 (17=16+1)
101011 (43=32+8+2+1)
---------------
111100 (60=32+16+8+4)
Signed arithmetic (w/ 2’s complement)
010001 (17=16+1)
101011 (-21: 2’s complement=010101=21)
---------------
111100 (2’s complement=000100=4, i.e. -4)
4
Binary Computation
Unsigned arithmetic
101111 (47)
011111 (31)
---------------
001110 (78?? Due to overflow, note that
62 cannot be represented
by a 6-bit unsigned number)
The carry is
discarded
Signed arithmetic (w/ 2’s complement)
101111 (-17 since 2’s complement=010001)
011111 (31)
---------------
001110 (14)
The carry is
discarded
BACKUP
6
Application of Two’s Complement
• The first Pocket CalculatorPocket Calculator “Curta”
used Two’s complement method for
subtractionsubtraction
• First complement the subtrahend
– Fill the left digits to be the same length
of the minuend
– Complemented number = (9 – digit)
• 4’s complement = 5
• 7’s complement = 2
• 0’s complement = 9
• Add 1 to the complemented number
• Perform an addition with the
minuend
7
Examples
• 13 – 7
– Two’s complement of 07 = 92 + 1 = 93
– 13 + 93 = 06 (ignore the leftmost carry digit)
• 817 – 123
– Two’s complement of 123 = 876 + 1 = 877
– 817 + 877 = 694 (ignore the leftmost carry digit)
• 78291 – 4982
– Two’s complement of 04982 = 95017 + 1 = 95018
– 78291 + 95018 = 73309 (ignore the leftmost carry digit)

More Related Content

PPT
Lec13 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Sh...
PPT
Lec11 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- De...
PPT
Lec16 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Fi...
PPT
Lec10 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Mu...
PPT
Datapath subsystem multiplication
PPTX
Understand data representation on CPU 1
PPT
Digital Logic & Design
PPTX
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc
Lec13 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Sh...
Lec11 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- De...
Lec16 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Fi...
Lec10 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Mu...
Datapath subsystem multiplication
Understand data representation on CPU 1
Digital Logic & Design
BOOTH ALGO, DIVISION(RESTORING _ NON RESTORING) etc etc

What's hot (20)

PPT
Ceng232 Decoder Multiplexer Adder
PDF
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
PPT
Numbersystemcont
PDF
Chapter 4
PPT
Arithmatic &Logic Unit
PPT
05 multiply divide
PPTX
ALL ABOUT NUMBER SYSTEMS
PDF
FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...
PPTX
Advanced encryption standard ug reseacrh
PPT
Arithmetic circuits
PDF
Datarepresentation2
PPT
Logic gates
PDF
Chapter 2
PPTX
Introducing to number system
PPTX
Booths algorithm for Multiplication
PDF
Lab 4 Three-Bit Binary Adder
PPTX
Data representation
PPTX
Arithmetic for Computers
DOC
Logic Gates O level Past Papers questions
Ceng232 Decoder Multiplexer Adder
Chapter 07 Digital Alrithmetic and Arithmetic Circuits
Numbersystemcont
Chapter 4
Arithmatic &Logic Unit
05 multiply divide
ALL ABOUT NUMBER SYSTEMS
FYBSC IT Digital Electronics Unit I Chapter I Number System and Binary Arithm...
Advanced encryption standard ug reseacrh
Arithmetic circuits
Datarepresentation2
Logic gates
Chapter 2
Introducing to number system
Booths algorithm for Multiplication
Lab 4 Three-Bit Binary Adder
Data representation
Arithmetic for Computers
Logic Gates O level Past Papers questions
Ad

Viewers also liked (20)

PPT
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
PPT
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
PPT
Lec5 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Branch Pred...
PPT
Lec1 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Intro
PPT
Lec6 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Can...
PPT
Lec14 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Se...
PPT
Lec20 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Da...
PPT
Lec3 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Performance
PPT
Lec8 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Qui...
PPT
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
PPT
Lec19 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Pr...
PPT
Lec9 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Com...
PPT
Lec3 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- CMO...
PPT
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
PPT
Lec1 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Pipelining
PPT
Lec12 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Ad...
PPT
Lec4 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- CMOS
PPT
Lec2 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ILP
PPT
Lec7 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Dynamic Sch...
PPT
Lec15 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Re...
Lec4 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ISA
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec5 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Branch Pred...
Lec1 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Intro
Lec6 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Can...
Lec14 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Se...
Lec20 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Da...
Lec3 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Performance
Lec8 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Qui...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec19 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Pr...
Lec9 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Com...
Lec3 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- CMO...
Lec17 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Me...
Lec1 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Pipelining
Lec12 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Ad...
Lec4 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- CMOS
Lec2 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- ILP
Lec7 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Dynamic Sch...
Lec15 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Re...
Ad

Similar to Lec2 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Number system (20)

PPTX
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
PPT
ch3a-binary-numbers.ppt
PPT
ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt
PPT
ch3a-binary-numbers.ppt
PPT
Review on Number Systems: Decimal, Binary, and Hexadecimal
PPT
binary-numbers.ppt
PPT
ch3a-binary-numbers.ppt
PPT
mmmmmmmmmmmmmmmmmmmmmmbinary-numbers.ppt
PPT
ch3a-binary-numbers.ppt
PPT
ch3a-binary-numbers.ppt-BINARY SYSTEM---
PPT
ch3a-binary-numbers.ppt
PPT
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
PPTX
computer organization-computer organization-
PDF
digital-electronics (1)_watermark.pdfhindi
PPT
number system.ppt
PPTX
digital-electronics.pptx
PPTX
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
PPTX
Switching Theory and Logic Circuits-LEC.pptx
PDF
Cse115 lecture01numbersystems
PPT
Number system and codes
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
ch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
Review on Number Systems: Decimal, Binary, and Hexadecimal
binary-numbers.ppt
ch3a-binary-numbers.ppt
mmmmmmmmmmmmmmmmmmmmmmbinary-numbers.ppt
ch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt-BINARY SYSTEM---
ch3a-binary-numbers.ppt
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
computer organization-computer organization-
digital-electronics (1)_watermark.pdfhindi
number system.ppt
digital-electronics.pptx
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
Switching Theory and Logic Circuits-LEC.pptx
Cse115 lecture01numbersystems
Number system and codes

More from Hsien-Hsin Sean Lee, Ph.D. (11)

PPT
Lec7 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Kar...
PPT
Lec5 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Boo...
PPT
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
PPT
Lec14 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech --- Coherence
PPT
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- SMP
PPT
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
PPT
Lec12 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- P6, Netbur...
PPT
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
PPT
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
PPT
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
PPT
Lec8 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Dynamic Sch...
Lec7 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Kar...
Lec5 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Boo...
Lec15 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- EPIC VLIW
Lec14 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech --- Coherence
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- SMP
Lec13 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Multicore
Lec12 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- P6, Netbur...
Lec11 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part3
Lec10 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part2
Lec9 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Memory part 1
Lec8 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Dynamic Sch...

Recently uploaded (20)

PDF
Colorful Illustrative Digital Education For Children Presentation.pdf
PDF
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
PPTX
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
PPTX
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
PPTX
sdn_based_controller_for_mobile_network_traffic_management1.pptx
PPTX
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
PPTX
Fundamentals of Computer.pptx Computer BSC
PPTX
English grade 10 st augusitne eoeoknkklm
PDF
How NGOs Save Costs with Affordable IT Rentals
PPTX
Syllabus Computer Six class curriculum s
PPTX
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
PPTX
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
PPTX
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
PDF
Cableado de Controladores Logicos Programables
PPT
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
PPTX
ERP good ERP good ERP good ERP good good ERP good ERP good
PPTX
quadraticequations-111211090004-phpapp02.pptx
PDF
YKS Chrome Plated Brass Safety Valve Product Catalogue
PPTX
udi-benefits-ggggggggfor-healthcare.pptx
PPTX
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew
Colorful Illustrative Digital Education For Children Presentation.pdf
Chapter -24-By Dr Sajid Ali Ansari 2021.pdf
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
sdn_based_controller_for_mobile_network_traffic_management1.pptx
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
Fundamentals of Computer.pptx Computer BSC
English grade 10 st augusitne eoeoknkklm
How NGOs Save Costs with Affordable IT Rentals
Syllabus Computer Six class curriculum s
了解新西兰毕业证(Wintec毕业证书)怀卡托理工学院毕业证存档可查的
02fdgfhfhfhghghhhhhhhhhhhhhhhhhhhhh.pptx
ATL_Arduino_Complete_Presentation_AI_Visuals.pptx
Cableado de Controladores Logicos Programables
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
ERP good ERP good ERP good ERP good good ERP good ERP good
quadraticequations-111211090004-phpapp02.pptx
YKS Chrome Plated Brass Safety Valve Product Catalogue
udi-benefits-ggggggggfor-healthcare.pptx
dhcp concept.pptxfeegrvewfegrgerhtrhtrhredew

Lec2 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- Number system

  • 1. ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean LeeProf. Hsien-Hsin Sean Lee School of Electrical and Computer EngineeringSchool of Electrical and Computer Engineering Georgia TechGeorgia Tech
  • 2. Decimal Number Representation • Example: 90134 (base-10, used by Homo Sapien) = 90000 + 0 + 100 + 30 + 4 = 9*104 + 0*103 + 1*102 + 3*101 + 4*100 • How did we get it? 901349013410 9013901310 44 90190110 33 909010 11 99 00
  • 3. Generic Number Representation • 90134 = 9*104 + 0*103 + 1*102 + 3*101 + 4*100 • A4A3A2A1A0 for base-10 (or radix-10) = A4*104 + A3*103 +A2*102 +A1*101 +A0*100 (A is coefficient; b is base) • Generalize for a given number NN w/ base-bb NN = An-1An-2 …A1A0 NN = An-1*bn-1 + An-2*bn-2 + … +A2*b2 +A0*b0 **Note that A < b**Note that A < b
  • 4. Counting numbers with base-bb 00 11 22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515 1616 1717 1818 1919 Base-10 9090 9191 9292 9393 9494 9595 9696 9797 9898 9999 ….. 100100 101101 102102 103103 104104 105105 106106 107107 108108 109109 How about Base-8 00 11 22 33 44 55 66 77 1010 1111 1212 1313 1414 1515 1616 1717 2020 2121 2222 2323 2424 2525 2626 2727 7070 7171 7272 7373 7474 7575 7676 7777 ….. 100100 101101 102102 103103 104104 105105 106106 107107 2020 2121 2222 2323 2424 2525 2626 2727 2828 2929
  • 7. How about base-22 00 = 0= 0 11 = 1= 1 1010 = 2= 2 1111 = 3= 3 100100 = 4= 4 101101 = 5= 5 110110 = 6= 6 111111 = 7= 7 10001000 = 8= 8 10011001 = 9= 9 10101010 = 10= 10 10111011 = 11= 11 11001100 = 12= 12 11011101 = 13= 13 11101110 = 14= 14 11111111 = 15= 15 BinaryBinary == DecimalDecimal
  • 8. Derive Numbers in Base-2 • Decimal (base-10) – (25)10 • Binary (base-2) – (11001)2 • Exercise 25252 12122 11 662 00 332 00 11 11
  • 9. Base-2 • Decimal (base-10) – (982)10 • Binary (base-2) – (1111010110)2 • Exercise
  • 10. 0 Base 8 • Decimal (base-10) – (982)10 • Octal (base-8) – (1726)8 • Exercise
  • 11. 1 Base 16 • Decimal (base-10) – (982)10 • Hexadecimal (base-16) • Hey, what do we do when we count to 10?? • 0 • 1 • 2 • 3 • 4 • 5 • 6 • 7 • 8 • 9 • 10 • 11 • 12 • 13 • 14 • 15 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
  • 12. 2 Base 16 • (982)10= (3d6)16 • (3d6)16 can be written as (0011 1101 0110)2 • We use Base-16 (or Hex) a lot in computer world – Ex: A 32-bit address can be written as 0xfe8a7d200xfe8a7d20 ((0x0x is an abbreviation of Hex)) – Or in binary formOr in binary form 1111_1110_1000_1010_0111_1101_0010_00001111_1110_1000_1010_0111_1101_0010_0000
  • 13. 3 Number Examples with Different Bases • Decimal (base-10) – (982)10 • Binary (base-2) – (01111010110)2 • Octal (base-8) – (1726)8 • Hexadecimal (base-16) – (3d6)16 • Others examples: – base-9 = (1321)9 – base-11 = (813)11 – base-17 = (36d)17
  • 14. 4 Convert between different bases • Convert a number base-x to base-y, e.g. (0100111)2 to (?)6 – First, convert from base-x to base-10 if x ≠ 10 – Then convert from base-10 to base-y 0100111 = 0∗26 + 1∗25 + 0∗24 + 0∗23 + 1∗22 + 1∗21 + 1∗20 = 39 39396 666 33 11 00 ∴ (0100111)2 = (103)6
  • 16. 6 Negative Number Representation • Options – Sign-magnitude – One’s Complement – Two’s Complement (we use this in this course)
  • 17. 7 Sign-magnitude • Use the most significant bit (MSB) to indicate the sign – 00: positive, 11: negative • Problem – Representing zeros? – Do not work in computation • We will NOT use it in this course ! +0 000 +1 001 +2 010 +3 011 -3 111 -2 110 -1 101 0 100
  • 18. 8 One’s Complement • Complement (flip) each bit in a binary number • Problem – Representing zeros? – Do not always work in computation • Ex: 111 + 001 = 000 → Incorrect ! • We will NOT use it in this course ! +0 000 +1 001 +2 010 +3 011 -3 100 -2 101 -1 110 0 111
  • 19. 9 Two’s Complement • ComplementComplement (flip) each bit in a binary number and adding 1adding 1, with overflow ignored • Work in computation perfectly • We will use it in this course ! 011 100 One’s complement 3 101 Add 1 -3 010 One’s complement 101-3 011 Add 1 3
  • 20. 0 Two’s Complement • ComplementComplement (flip) each bit in a binary number and adding 1adding 1, with overflow ignored • Work in computation perfectly • We will use it in this course ! 0 000 +1 001 -1 111 +2 010 -2 110 +3 011 -3 101 ?? 100 100 011 One’s complement 100 Add 1 The same 100 represents both 4 and -4 which is no good
  • 21. 1 Two’s Complement • ComplementComplement (flip) each bit in a binary number and adding 1adding 1, with overflow ignored • Work in computation perfectly • We will use it in this course ! 0 000 +1 001 -1 1111 +2 010 -2 1110 +3 011 -3 1101 --4 1100 100 011 One’s complement 100 Add 1 MSB = 1 for negative Number, thus 100 represents -4
  • 22. 2 Range of Numbers • An N-bit number – Unsigned: 0 .. (2 N -1) – Signed: -2 N-1 .. (2 N-1 -1) • Example: 4-bit 1110 (-8) 0111 (7) Signed numbers 0000 (0) 1111 (15)Unsigned numbers
  • 23. 3 Binary Computation 010001 (17=16+1) 001011 (11=8+2+1) --------------- 011100 (28=16+8+4) Unsigned arithmetic 010001 (17=16+1) 101011 (43=32+8+2+1) --------------- 111100 (60=32+16+8+4) Signed arithmetic (w/ 2’s complement) 010001 (17=16+1) 101011 (-21: 2’s complement=010101=21) --------------- 111100 (2’s complement=000100=4, i.e. -4)
  • 24. 4 Binary Computation Unsigned arithmetic 101111 (47) 011111 (31) --------------- 001110 (78?? Due to overflow, note that 62 cannot be represented by a 6-bit unsigned number) The carry is discarded Signed arithmetic (w/ 2’s complement) 101111 (-17 since 2’s complement=010001) 011111 (31) --------------- 001110 (14) The carry is discarded
  • 26. 6 Application of Two’s Complement • The first Pocket CalculatorPocket Calculator “Curta” used Two’s complement method for subtractionsubtraction • First complement the subtrahend – Fill the left digits to be the same length of the minuend – Complemented number = (9 – digit) • 4’s complement = 5 • 7’s complement = 2 • 0’s complement = 9 • Add 1 to the complemented number • Perform an addition with the minuend
  • 27. 7 Examples • 13 – 7 – Two’s complement of 07 = 92 + 1 = 93 – 13 + 93 = 06 (ignore the leftmost carry digit) • 817 – 123 – Two’s complement of 123 = 876 + 1 = 877 – 817 + 877 = 694 (ignore the leftmost carry digit) • 78291 – 4982 – Two’s complement of 04982 = 95017 + 1 = 95018 – 78291 + 95018 = 73309 (ignore the leftmost carry digit)