SlideShare a Scribd company logo
Number Systems
DECIMAL, BINARY, AND
HEXADECIMAL
1
Base-N Number System
 Base N
 N Digits: 0, 1, 2, 3, 4, 5, …, N-1
 Example: 1045N
 Positional Number System

2
• Digit do is the least significant digit (LSD).
• Digit dn-1 is the most significant digit (MSD).
1 4 3 2 1 0
1 4 3 2 1 0
n
n
N N N N N N
d d d d d d




Decimal Number System
 Base 10
 Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 Example: 104510
 Positional Number System
 Digit d0 is the least significant digit (LSD).
 Digit dn-1 is the most significant digit (MSD).
3
1 4 3 2 1 0
1 4 3 2 1 0
10 10 10 10 1010
n
n
d d d d d d




Binary Number System
 Base 2
 Two Digits: 0, 1
 Example: 10101102
 Positional Number System
 Binary Digits are called Bits
 Bit bo is the least significant bit (LSB).
 Bit bn-1 is the most significant bit (MSB).
4
1 4 3 2 1 0
1 4 3 2 1 0
2 2 2 2 2 2
n
n
b b b b b b




 nybble = 4 bits
 byte = 8 bits
 (short) word = 2 bytes = 16 bits
 (double) word = 4 bytes = 32 bits
 (long) word = 8 bytes = 64 bits
 1K (kilo or “kibi”) = 1,024
 1M (mega or “mebi”) = (1K)*(1K) = 1,048,576
 1G (giga or “gibi”) = (1K)*(1M) =
1,073,741,824
 1 Petabyte = 1024 Terabytes.
 1 terabyte (TB) equals 1,000 gigabytes
(GB) or 1,000,000 megabytes (MB).
5
NVIDIA A100?
Upto 80
gigabytes (GB)
16 and 32GB
configurations,
and offers the
performance of up
to 32 CPUs in a
single GPU.
Hexadecimal Number
System
 Base 16
 Sixteen Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
 Example: EF5616
 Positional Number System

6
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
1 4 3 2 1 0
16 16 16 16 1616
n

Binary Addition 7
•Single Bit Addition Table
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 Note “carry”
Hex Addition 8
• 4-bit Addition
4 + 4 = 8
4 + 8 = C
8 + 7 = F
F + E = 1D Note “carry”,
Refer HEX Addition Table
Hex Digit Addition Table
+ 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0 1 2 3 4 5 6 7 8 9 A B C D E F
1 1 2 3 4 5 6 7 8 9 A B C D E F 10
2 2 3 4 5 6 7 8 9 A B C D E F 10 11
3 3 4 5 6 7 8 9 A B C D E F 10 11 12
4 4 5 6 7 8 9 A B C D E F 10 11 12 13
5 5 6 7 8 9 A B C D E F 10 11 12 13 14
6 6 7 8 9 A B C D E F 10 11 12 13 14 15
7 7 8 9 A B C D E F 10 11 12 13 14 15 16
8 8 9 A B C D E F 10 11 12 13 14 15 16 17
9 9 A B C D E F 10 11 12 13 14 15 16 17 18
A A B C D E F 10 11 12 13 14 15 16 17 18 19
B B C D E F 10 11 12 13 14 15 16 17 18 19 1A
C C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B
D D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C
E E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
F F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E
9
1’s Complements
 1’s complement (or Ones’
Complement)
To calculate the 1’s complement
of a binary number just “flip”
each bit of the original binary
number.
E.g. 0  1 , 1  0
 01010100100  10101011011
10
Why choose 2’s
complement?
11
2’s Complements
 2’s complement
 To calculate the 2’s complement just calculate the 1’s
complement, then add 1.
01010100100  10101011011 + 1=
10101011100
 Handy Trick: Leave all of the least significant 0’s and first 1
unchanged, and then “flip” the bits for all other digits.
 Eg: 01010100100 -> 10101011100
12
Complements
 Note the 2’s complement of the 2’s complement
is just the original number N
 EX: let N = 01010100100
 (2’s comp of N) = M = 10101011100
 (2’s comp of M) = 01010100100 = N
13
Signed Binary Numbers
 Two methods:
 First method: sign-magnitude
 Use one bit to represent the sign
 0 = positive, 1 = negative
 Remaining bits are used to represent the
magnitude
 Range - (2n-1
– 1) to 2n-1
- 1
where n=number of digits
 Example: Let n=4: Range is –7 to 7 or
 1111 to 0111
14
Signed Binary Numbers
 Second method: Two’s-complement
 Use the 2’s complement of N to represent
-N
 Note: MSB is 0 if positive and 1 if negative
 Range - 2n-1
to 2n-1
-1
where n=number of digits
 Example: Let n=4: Range is –8 to 7
Or 1000 to 0111
15
Signed Numbers – 4-bit
example
Decimal 2’s comp Sign-Mag
7 0111 0111
6 0110 0110
5 0101 0101
4 0100 0100
3 0011 0011
2 0010 0010
1 0001 0001
0 0000 0000
16
Pos 0
Signed Numbers-4 bit
example
Decimal 2’s comp Sign-Mag
-8 1000 N/A
-7 1001 1111
-6 1010 1110
-5 1011 1101
-4 1100 1100
-3 1101 1011
-2 1110 1010
-1 1111 1001
-0 0000 (= +0) 1000
17
Notes:
 “Humans” normally use sign-magnitude
representation for signed numbers
 Eg: Positive numbers: +N or N
 Negative numbers: -N
 Computers generally use two’s-
complement representation for signed
numbers
 First bit still indicates positive or negative.
 If the number is negative, take 2’s
complement to determine its magnitude
 Or, just add up the values of bits at their
positions, remembering that the first bit is
implicitly negative.
18
Examples
 Let N=4: two’s-complement
 What is the decimal equivalent of
01012
Since MSB is 0, number is positive
01012 = 4+1 = +510
 What is the decimal equivalent of
11012 =
 Since MSB is one, number is negative
 Must calculate its 2’s complement
 11012 = −(0010+1)= − 00112 or −310
19
Very Important!!! – Unless otherwise stated, assume
two’s-complement numbers for all problems, quizzes,
HW’s, etc.
The first digit will not necessarily
be explicitly underlined.
20
Arithmetic Subtraction
 Borrow Method
 This is the technique you learned in grade school
 For binary numbers, we have

21
0 - 0 = 0
1 - 0 = 1
1 - 1 = 0
0 - 1 = 1 with a “borrow”
1
Binary Subtraction
 Note:
 A – (+B) = A + (-B)
 A – (-B) = A + (-(-B))= A + (+B)
 In other words, we can “subtract” B from A by
“adding” –B to A.
 However, -B is just the 2’s complement of B, so to
perform subtraction, we
 1. Calculate the 2’s complement of B
 2. Add A + (-B)
22
Binary Subtraction -
Example
 Let n=4, A=01002 (410), and
B=00102 (210)
 Let’s find A+B, A-B and B-A
23
0 1 0 0
+ 0 0 1 0
 (4)10
 (2)10
0 11 0 6
A+B
Binary Subtraction -
Example
24
0 1 0 0
- 0 0 1 0
 (4)10
 (2)10
10 0 1 0 2
A-B
0 1 0 0
+ 1 1 1 0
 (4)10
 (-2)10
A+ (-B)
“Throw this bit” away since n=4
Binary Subtraction -
Example
25
0 0 1 0
- 0 1 0 0
 (2)10
 (4)10
1 1 1 0 -2
B-A
0 0 1 0
+ 1 1 0 0
 (2)10
 (-4)10
B + (-A)
1 1 1 02 = - 0 0 1 02 = -210
Number Conversions
26
Binary-to-Decimal
Conversion
 The decimal value of any binary number can be
found by adding the weights of all bits that are 1
and discarding the weights of all bits that are 0.
 Example
 Let’s convert the binary whole number 101101 to
decimal.
 Weight: 2 2 2 2 2 2º
   
 Binary no: 1 0 1 1 0 1
 101101= 2 + 2 + 2 + 2º = 32+8+4+1=45
  
27
Decimal-to-Binary
Conversion
 One way to find the binary number that is equivalent
to a given decimal number is to determine the set of
binary weights whose sum is equal to the decimal
number. For example decimal number 9, can be
expressed as the sum of binary weights as follows:
 9 = 8 + 1 or 9 = 2³ + 2º
 Placing 1s in the appropriate weight positions, 2³ and
 2º, and 0s in the 2² and 2¹ positions determines the
binary number for decimal 9.
 2³ 2² 2¹ 2º
 1 0 0 1 Binary number for nine
28
Binary-to-Hexadecimal
Conversion
 Simply break the binary number into 4-bit groups,
starting at the right-most bit and replace each 4-
bit group with the equivalent hexadecimal
symbol as in the following example.
 Convert the binary number to hexadecimal:
 1100101001010111
 Solution:
 1100 1010 0101 0111

 C A 5 7 = CA57
29
Hexadecimal-to-
Decimal Conversion
 One way to find the decimal equivalent of a
hexadecimal number is to first convert the
hexadecimal number to binary and then convert
from binary to decimal.
 Convert the hexadecimal number 1C to decimal:
 1 C
 0001 1100 = 2 + 2
 ³ + 2² = 16 +8+4 = 28
30
 Convert the decimal number 650 to hexadecimal
by repeated division by 16.
 650 = 40.625 0.625 x 16 = 10 = A (LSD)
 16
 40 = 2.5 0.5 x 16 = 8 = 8
 16
 2 = 0.125 0.125 x 16 = 2 = 2 (MSD)
 16
 The hexadecimal number is 28A
31
Octal System
 Like the hexadecimal system, the octal system provides a
convenient way to express binary numbers and codes.
 However, it is used less frequently than hexadecimal in
conjunction with computers and microprocessors to
express binary quantities for input and output purposes.
 The octal system is composed of eight digits, which are:
 0, 1, 2, 3, 4, 5, 6, 7
 To count above 7, begin another column and start over:
 10, 11, 12, 13, 14, 15, 16, 17, 20, 21 and so on.
 Counting in octal is similar to counting in decimal, except
that the digits 8 and 9 are not used.
32
Octal-to-Decimal
Conversion
 Since the octal number system has a base of
eight, each successive digit position is an
increasing power of eight, beginning in the right-
most column with 8º. The evaluation
 Of an octal number in terms of its decimal
equivalent is accomplished by multiplying each
digit by its weight and summing the products.
 Let’s convert octal number 2374 in decimal
number.
 Weight 8³ 8² 8 8º
 Octal number 2 3 7 4
 2374 = (2 x 8³) + (3 x 8²) + (7 x 8) + (4 x 8º)=1276
33
Decimal-to-Octal
Conversion
 A method of converting a decimal number to an octal
number is the repeated division-by-8 method, which is
similar to the method used in the conversion of decimal
numbers to binary or to hexadecimal.
 Let’s convert the decimal number 359 to octal. Each
successive division by 8 yields a remainder that becomes a
digit in the equivalent octal number. The first remainder
generated is the least significant digit (LSD).
 359 = 44.875 0.875 x 8 = 7 (LSD)
 8
 44 = 5.5 0.5 x 8 = 4
 8
5 = 0.625 0.625 x 8 = 5 (MSD)
 8
 The number is 547.
34
Octal-to-Binary
Conversion
 Because each octal digit can be represented by
a 3-bit binary number, it is very easy to convert
from octal to binary..
 Octal/Binary Conversion
 Octal Digit 0 1 2 3 4 5 6 7
 Binary 000 001 010 011 100 101 110 111
Let’s convert the octal numbers 25 and 140.
2 5 1 4 0
010 101 001 100 000
35

More Related Content

PPT
number system.ppt
ShrutiSharma485933
 
PPT
ch3a-binary-numbers.ppt
RabiaAsif31
 
PPT
ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt
anilmallah76
 
PPT
ch3a-binary-numbers.ppt
RAJKUMARP63
 
PPT
ch3a-binary-numbers.ppt
ssuser52a19e
 
PPT
Review on Number Systems: Decimal, Binary, and Hexadecimal
UtkirjonUbaydullaev1
 
PPT
mmmmmmmmmmmmmmmmmmmmmmbinary-numbers.ppt
AdityaGupta221734
 
PPT
ch3a-binary-numbers.ppt
Suganthi Vasanth Raj
 
number system.ppt
ShrutiSharma485933
 
ch3a-binary-numbers.ppt
RabiaAsif31
 
ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt ch3a-binary-numbers.ppt
anilmallah76
 
ch3a-binary-numbers.ppt
RAJKUMARP63
 
ch3a-binary-numbers.ppt
ssuser52a19e
 
Review on Number Systems: Decimal, Binary, and Hexadecimal
UtkirjonUbaydullaev1
 
mmmmmmmmmmmmmmmmmmmmmmbinary-numbers.ppt
AdityaGupta221734
 
ch3a-binary-numbers.ppt
Suganthi Vasanth Raj
 

Similar to Number system on various number tyoes decimal (20)

PPT
binary-numbers.ppt
MarlonMagtibay2
 
PPTX
Number system_lecnsjxnxnxnxnxnxnxnnxnxnjdjdn
MarlboroRed2
 
PPTX
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
naveenkaueee
 
PPTX
Number_system_B.pharm_2nd_BP205T_Unit_1_Ravi.pptx
ravisharma3100
 
PPTX
1. NUMBER SYSTEM.pptx Computer Applications in Pharmacy
Vedika Narvekar
 
PPT
Lecture 2 ns
Rabiul Sarker
 
PPT
ch3a-binary-numbers.ppt
MUNAZARAZZAQELEA
 
PPT
Logic Design - Chapter 1: Number Systems and Codes
Gouda Mando
 
PDF
Cse115 lecture01numbersystems
Md. Ashikur Rahman
 
PPTX
Number system
Mantra VLSI
 
PPTX
Data Representation
Education Front
 
PPTX
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
FiraolGadissa
 
PDF
INTRODUCTION TO NUMBER SYSTEMS 2024-25.pdf
mrld6995
 
PPTX
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
Surendra Loya
 
PPTX
Data Representation
Education Front
 
PDF
Digital and Logic Design Chapter 1 binary_systems
Imran Waris
 
PPT
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
TMaungLwin
 
PPTX
ADE UNIT-III (Digital Fundamentals).pptx
KUMARS641064
 
PPT
45196656565656565656565656565656565656566.ppt
Harshal Vaidya
 
PPTX
Number system conversion
Kawsar Hamid Sumon
 
binary-numbers.ppt
MarlonMagtibay2
 
Number system_lecnsjxnxnxnxnxnxnxnnxnxnjdjdn
MarlboroRed2
 
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
naveenkaueee
 
Number_system_B.pharm_2nd_BP205T_Unit_1_Ravi.pptx
ravisharma3100
 
1. NUMBER SYSTEM.pptx Computer Applications in Pharmacy
Vedika Narvekar
 
Lecture 2 ns
Rabiul Sarker
 
ch3a-binary-numbers.ppt
MUNAZARAZZAQELEA
 
Logic Design - Chapter 1: Number Systems and Codes
Gouda Mando
 
Cse115 lecture01numbersystems
Md. Ashikur Rahman
 
Number system
Mantra VLSI
 
Data Representation
Education Front
 
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
FiraolGadissa
 
INTRODUCTION TO NUMBER SYSTEMS 2024-25.pdf
mrld6995
 
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
Surendra Loya
 
Data Representation
Education Front
 
Digital and Logic Design Chapter 1 binary_systems
Imran Waris
 
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
TMaungLwin
 
ADE UNIT-III (Digital Fundamentals).pptx
KUMARS641064
 
45196656565656565656565656565656565656566.ppt
Harshal Vaidya
 
Number system conversion
Kawsar Hamid Sumon
 
Ad

Recently uploaded (20)

PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Zero Carbon Building Performance standard
BassemOsman1
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
Ad

Number system on various number tyoes decimal

  • 2. Base-N Number System  Base N  N Digits: 0, 1, 2, 3, 4, 5, …, N-1  Example: 1045N  Positional Number System  2 • Digit do is the least significant digit (LSD). • Digit dn-1 is the most significant digit (MSD). 1 4 3 2 1 0 1 4 3 2 1 0 n n N N N N N N d d d d d d    
  • 3. Decimal Number System  Base 10  Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9  Example: 104510  Positional Number System  Digit d0 is the least significant digit (LSD).  Digit dn-1 is the most significant digit (MSD). 3 1 4 3 2 1 0 1 4 3 2 1 0 10 10 10 10 1010 n n d d d d d d    
  • 4. Binary Number System  Base 2  Two Digits: 0, 1  Example: 10101102  Positional Number System  Binary Digits are called Bits  Bit bo is the least significant bit (LSB).  Bit bn-1 is the most significant bit (MSB). 4 1 4 3 2 1 0 1 4 3 2 1 0 2 2 2 2 2 2 n n b b b b b b    
  • 5.  nybble = 4 bits  byte = 8 bits  (short) word = 2 bytes = 16 bits  (double) word = 4 bytes = 32 bits  (long) word = 8 bytes = 64 bits  1K (kilo or “kibi”) = 1,024  1M (mega or “mebi”) = (1K)*(1K) = 1,048,576  1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824  1 Petabyte = 1024 Terabytes.  1 terabyte (TB) equals 1,000 gigabytes (GB) or 1,000,000 megabytes (MB). 5 NVIDIA A100? Upto 80 gigabytes (GB) 16 and 32GB configurations, and offers the performance of up to 32 CPUs in a single GPU.
  • 6. Hexadecimal Number System  Base 16  Sixteen Digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F  Example: EF5616  Positional Number System  6 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F 1 4 3 2 1 0 16 16 16 16 1616 n 
  • 7. Binary Addition 7 •Single Bit Addition Table 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 Note “carry”
  • 8. Hex Addition 8 • 4-bit Addition 4 + 4 = 8 4 + 8 = C 8 + 7 = F F + E = 1D Note “carry”, Refer HEX Addition Table
  • 9. Hex Digit Addition Table + 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 0 1 2 3 4 5 6 7 8 9 A B C D E F 1 1 2 3 4 5 6 7 8 9 A B C D E F 10 2 2 3 4 5 6 7 8 9 A B C D E F 10 11 3 3 4 5 6 7 8 9 A B C D E F 10 11 12 4 4 5 6 7 8 9 A B C D E F 10 11 12 13 5 5 6 7 8 9 A B C D E F 10 11 12 13 14 6 6 7 8 9 A B C D E F 10 11 12 13 14 15 7 7 8 9 A B C D E F 10 11 12 13 14 15 16 8 8 9 A B C D E F 10 11 12 13 14 15 16 17 9 9 A B C D E F 10 11 12 13 14 15 16 17 18 A A B C D E F 10 11 12 13 14 15 16 17 18 19 B B C D E F 10 11 12 13 14 15 16 17 18 19 1A C C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B D D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C E E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D F F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 9
  • 10. 1’s Complements  1’s complement (or Ones’ Complement) To calculate the 1’s complement of a binary number just “flip” each bit of the original binary number. E.g. 0  1 , 1  0  01010100100  10101011011 10
  • 12. 2’s Complements  2’s complement  To calculate the 2’s complement just calculate the 1’s complement, then add 1. 01010100100  10101011011 + 1= 10101011100  Handy Trick: Leave all of the least significant 0’s and first 1 unchanged, and then “flip” the bits for all other digits.  Eg: 01010100100 -> 10101011100 12
  • 13. Complements  Note the 2’s complement of the 2’s complement is just the original number N  EX: let N = 01010100100  (2’s comp of N) = M = 10101011100  (2’s comp of M) = 01010100100 = N 13
  • 14. Signed Binary Numbers  Two methods:  First method: sign-magnitude  Use one bit to represent the sign  0 = positive, 1 = negative  Remaining bits are used to represent the magnitude  Range - (2n-1 – 1) to 2n-1 - 1 where n=number of digits  Example: Let n=4: Range is –7 to 7 or  1111 to 0111 14
  • 15. Signed Binary Numbers  Second method: Two’s-complement  Use the 2’s complement of N to represent -N  Note: MSB is 0 if positive and 1 if negative  Range - 2n-1 to 2n-1 -1 where n=number of digits  Example: Let n=4: Range is –8 to 7 Or 1000 to 0111 15
  • 16. Signed Numbers – 4-bit example Decimal 2’s comp Sign-Mag 7 0111 0111 6 0110 0110 5 0101 0101 4 0100 0100 3 0011 0011 2 0010 0010 1 0001 0001 0 0000 0000 16 Pos 0
  • 17. Signed Numbers-4 bit example Decimal 2’s comp Sign-Mag -8 1000 N/A -7 1001 1111 -6 1010 1110 -5 1011 1101 -4 1100 1100 -3 1101 1011 -2 1110 1010 -1 1111 1001 -0 0000 (= +0) 1000 17
  • 18. Notes:  “Humans” normally use sign-magnitude representation for signed numbers  Eg: Positive numbers: +N or N  Negative numbers: -N  Computers generally use two’s- complement representation for signed numbers  First bit still indicates positive or negative.  If the number is negative, take 2’s complement to determine its magnitude  Or, just add up the values of bits at their positions, remembering that the first bit is implicitly negative. 18
  • 19. Examples  Let N=4: two’s-complement  What is the decimal equivalent of 01012 Since MSB is 0, number is positive 01012 = 4+1 = +510  What is the decimal equivalent of 11012 =  Since MSB is one, number is negative  Must calculate its 2’s complement  11012 = −(0010+1)= − 00112 or −310 19
  • 20. Very Important!!! – Unless otherwise stated, assume two’s-complement numbers for all problems, quizzes, HW’s, etc. The first digit will not necessarily be explicitly underlined. 20
  • 21. Arithmetic Subtraction  Borrow Method  This is the technique you learned in grade school  For binary numbers, we have  21 0 - 0 = 0 1 - 0 = 1 1 - 1 = 0 0 - 1 = 1 with a “borrow” 1
  • 22. Binary Subtraction  Note:  A – (+B) = A + (-B)  A – (-B) = A + (-(-B))= A + (+B)  In other words, we can “subtract” B from A by “adding” –B to A.  However, -B is just the 2’s complement of B, so to perform subtraction, we  1. Calculate the 2’s complement of B  2. Add A + (-B) 22
  • 23. Binary Subtraction - Example  Let n=4, A=01002 (410), and B=00102 (210)  Let’s find A+B, A-B and B-A 23 0 1 0 0 + 0 0 1 0  (4)10  (2)10 0 11 0 6 A+B
  • 24. Binary Subtraction - Example 24 0 1 0 0 - 0 0 1 0  (4)10  (2)10 10 0 1 0 2 A-B 0 1 0 0 + 1 1 1 0  (4)10  (-2)10 A+ (-B) “Throw this bit” away since n=4
  • 25. Binary Subtraction - Example 25 0 0 1 0 - 0 1 0 0  (2)10  (4)10 1 1 1 0 -2 B-A 0 0 1 0 + 1 1 0 0  (2)10  (-4)10 B + (-A) 1 1 1 02 = - 0 0 1 02 = -210
  • 27. Binary-to-Decimal Conversion  The decimal value of any binary number can be found by adding the weights of all bits that are 1 and discarding the weights of all bits that are 0.  Example  Let’s convert the binary whole number 101101 to decimal.  Weight: 2 2 2 2 2 2º      Binary no: 1 0 1 1 0 1  101101= 2 + 2 + 2 + 2º = 32+8+4+1=45    27
  • 28. Decimal-to-Binary Conversion  One way to find the binary number that is equivalent to a given decimal number is to determine the set of binary weights whose sum is equal to the decimal number. For example decimal number 9, can be expressed as the sum of binary weights as follows:  9 = 8 + 1 or 9 = 2³ + 2º  Placing 1s in the appropriate weight positions, 2³ and  2º, and 0s in the 2² and 2¹ positions determines the binary number for decimal 9.  2³ 2² 2¹ 2º  1 0 0 1 Binary number for nine 28
  • 29. Binary-to-Hexadecimal Conversion  Simply break the binary number into 4-bit groups, starting at the right-most bit and replace each 4- bit group with the equivalent hexadecimal symbol as in the following example.  Convert the binary number to hexadecimal:  1100101001010111  Solution:  1100 1010 0101 0111   C A 5 7 = CA57 29
  • 30. Hexadecimal-to- Decimal Conversion  One way to find the decimal equivalent of a hexadecimal number is to first convert the hexadecimal number to binary and then convert from binary to decimal.  Convert the hexadecimal number 1C to decimal:  1 C  0001 1100 = 2 + 2  ³ + 2² = 16 +8+4 = 28 30
  • 31.  Convert the decimal number 650 to hexadecimal by repeated division by 16.  650 = 40.625 0.625 x 16 = 10 = A (LSD)  16  40 = 2.5 0.5 x 16 = 8 = 8  16  2 = 0.125 0.125 x 16 = 2 = 2 (MSD)  16  The hexadecimal number is 28A 31
  • 32. Octal System  Like the hexadecimal system, the octal system provides a convenient way to express binary numbers and codes.  However, it is used less frequently than hexadecimal in conjunction with computers and microprocessors to express binary quantities for input and output purposes.  The octal system is composed of eight digits, which are:  0, 1, 2, 3, 4, 5, 6, 7  To count above 7, begin another column and start over:  10, 11, 12, 13, 14, 15, 16, 17, 20, 21 and so on.  Counting in octal is similar to counting in decimal, except that the digits 8 and 9 are not used. 32
  • 33. Octal-to-Decimal Conversion  Since the octal number system has a base of eight, each successive digit position is an increasing power of eight, beginning in the right- most column with 8º. The evaluation  Of an octal number in terms of its decimal equivalent is accomplished by multiplying each digit by its weight and summing the products.  Let’s convert octal number 2374 in decimal number.  Weight 8³ 8² 8 8º  Octal number 2 3 7 4  2374 = (2 x 8³) + (3 x 8²) + (7 x 8) + (4 x 8º)=1276 33
  • 34. Decimal-to-Octal Conversion  A method of converting a decimal number to an octal number is the repeated division-by-8 method, which is similar to the method used in the conversion of decimal numbers to binary or to hexadecimal.  Let’s convert the decimal number 359 to octal. Each successive division by 8 yields a remainder that becomes a digit in the equivalent octal number. The first remainder generated is the least significant digit (LSD).  359 = 44.875 0.875 x 8 = 7 (LSD)  8  44 = 5.5 0.5 x 8 = 4  8 5 = 0.625 0.625 x 8 = 5 (MSD)  8  The number is 547. 34
  • 35. Octal-to-Binary Conversion  Because each octal digit can be represented by a 3-bit binary number, it is very easy to convert from octal to binary..  Octal/Binary Conversion  Octal Digit 0 1 2 3 4 5 6 7  Binary 000 001 010 011 100 101 110 111 Let’s convert the octal numbers 25 and 140. 2 5 1 4 0 010 101 001 100 000 35