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
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
number system.ppt
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

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

PPT
ch3a-binary-numbers.ppt
PPTX
Number system_lecnsjxnxnxnxnxnxnxnnxnxnjdjdn
PPT
ch3a-binary-numbers.ppt-BINARY SYSTEM---
PPTX
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
PPTX
Number_system_B.pharm_2nd_BP205T_Unit_1_Ravi.pptx
PPTX
1. NUMBER SYSTEM.pptx Computer Applications in Pharmacy
PPT
Lecture 2 ns
PPT
ch3a-binary-numbers.ppt
PPT
Logic Design - Chapter 1: Number Systems and Codes
PDF
Cse115 lecture01numbersystems
PPTX
Number system
PPTX
Data Representation
PPTX
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
PDF
INTRODUCTION TO NUMBER SYSTEMS 2024-25.pdf
PPTX
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
PPTX
Data Representation
PDF
Digital and Logic Design Chapter 1 binary_systems
PPT
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
PPTX
ADE UNIT-III (Digital Fundamentals).pptx
PPT
45196656565656565656565656565656565656566.ppt
ch3a-binary-numbers.ppt
Number system_lecnsjxnxnxnxnxnxnxnnxnxnjdjdn
ch3a-binary-numbers.ppt-BINARY SYSTEM---
DEC Unit 1 Full-1.pptx Boolean Algebra and Logic gates
Number_system_B.pharm_2nd_BP205T_Unit_1_Ravi.pptx
1. NUMBER SYSTEM.pptx Computer Applications in Pharmacy
Lecture 2 ns
ch3a-binary-numbers.ppt
Logic Design - Chapter 1: Number Systems and Codes
Cse115 lecture01numbersystems
Number system
Data Representation
ARCsxfhcjkvmnfxcgbfgcxhvbxdfzxcgbfxgcvbnx3.pptx
INTRODUCTION TO NUMBER SYSTEMS 2024-25.pdf
chapter1digitalsystemsandbinarynumbers-151021072016-lva1-app6891.pptx
Data Representation
Digital and Logic Design Chapter 1 binary_systems
Basic Digital_Systems_and_Binary_Numbers Sample.ppt
ADE UNIT-III (Digital Fundamentals).pptx
45196656565656565656565656565656565656566.ppt
Ad

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
DOCX
573137875-Attendance-Management-System-original
PPT
Mechanical Engineering MATERIALS Selection
PDF
Digital Logic Computer Design lecture notes
PDF
Well-logging-methods_new................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Geodesy 1.pptx...............................................
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Sustainable Sites - Green Building Construction
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Welding lecture in detail for understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
573137875-Attendance-Management-System-original
Mechanical Engineering MATERIALS Selection
Digital Logic Computer Design lecture notes
Well-logging-methods_new................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Lesson 3_Tessellation.pptx finite Mathematics
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Geodesy 1.pptx...............................................
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Sustainable Sites - Green Building Construction
Model Code of Practice - Construction Work - 21102022 .pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Welding lecture in detail for understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
OOP with Java - Java Introduction (Basics)
UNIT 4 Total Quality Management .pptx
Structs to JSON How Go Powers REST APIs.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
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