0% found this document useful (0 votes)
5 views55 pages

CS-1101 - DLD - FALL 2024 - Lect 4-9

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

CS-1101 - DLD - FALL 2024 - Lect 4-9

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

SUGGESTED READING

CHAPTER 2
1
TOPICS:
Decimal Numbers
Binary Numbers
Decimal-to-Binary Conversion
Hexadecimal Numbers
Binary Arithmetic
Complements of Binary Numbers
Binary Coded Decimal (BCD)
Digital Codes Concepts
Error Codes

Lecture # 4-9
DR. NAJEEB UR REHMAN
FROM ZERO TO ONE Number Systems
• Decimal
– Base 10
• Binary
– Base 2
• Hexadecimal
– Base 16

Chapter 1 <2>
Decimal Numbers (Base 10)
3
 You are familiar with the decimal number system because you use
decimal numbers every day.
 Weighted structure of Decimal Number systems ?
 Decimal number system uses ten digits, 0 through 9 to represents a
certain quantity.
 These ten digits do not limit you to express any Large or small
number
 How you will Read (pronounce) 23 !
 The position of each digit in a decimal
number indicates the magnitude of
the quantity represented and can be
assigned a weight.
FROM ZERO TO ONE Review: Decimal Numbers
• Base 10 (our everyday number system)

1000's column

10's column
1's column
100's column
537410 =

Base 10

Chapter 1 <4>
FROM ZERO TO ONE Review: Decimal Numbers
• Base 10 (our everyday number system)

1000's column

10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones

Base 10

Chapter 1 <5>
Binary Numbers (Base 2)
6
 Binarysystem has only two digits
(Base-two system)
 The two binary digits (bits) are 1 and
0.
 Theposition of a 1 or 0 in a
binary number indicates its
weight, or value within the
number, just as in decimal
number systems.
 Theweights in a binary number
are based on powers of two.
The Weighting Structure of Binary Numbers
7
 A binary number is a weighted number
 Every Digit in Binary Number has some associated Weight.
 The right-most bit is the LSB (least significant bit) in a binary whole
number
 Weight of = 1
 The weights increase from right to left by a power of two for each bit.
 The left-most bit is the MSB (most significant bit)
 its weight depends on the size (Length) of the binary number.
FROM ZERO TO ONE Decimal and Binary Numbers
• Base 10 (our everyday number system)

1000's column

10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones

• Base 2: Binary numbers


8's column

2's column
1's column
4's column

11012 =

Base 2
Chapter 1 <8>
FROM ZERO TO ONE Decimal and Binary Numbers
• Base 10 (our everyday number system)

1000's column

10's column
1's column
100's column
537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100
five three seven four
thousands hundreds tens ones

• Base 2: Binary numbers


8's column

2's column
1's column
4's column

11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310
one one no one
eight four two one

Base 2
Chapter 1 <9>
FROM ZERO TO ONE Powers of Two
• 20 = • 28 =
• 21 = • 29 =
• 22 = • 210 =
• 23 = • 211 =
• 24 = • 212 =
• 25 = • 213 =
• 26 = • 214 =
• 27 = • 215 =

Chapter 1 <10>
FROM ZERO TO ONE Powers of Two
• 20 = 1 • 28 = 256
• 21 = 2 • 29 = 512
• 22 = 4 • 210 = 1024
• 23 = 8 • 211 = 2048
• 24 = 16 • 212 = 4096
• 25 = 32 • 213 = 8192
• 26 = 64 • 214 = 16384
• 27 = 128 • 215 = 32768
• Handy to memorize up to 29
Chapter 1 <11>
FROM ZERO TO ONE Binary to Decimal Conversion
• Binary to decimal conversion:
– Convert 100112 to decimal

Chapter 1 <12>
FROM ZERO TO ONE Binary to Decimal Conversion
• Binary to decimal conversion:
– Convert 100112 to decimal
– 16×1 + 8×0 + 4×0 + 2×1 + 1×1 = 1910

Chapter 1 <13>
FROM ZERO TO ONE Decimal to Binary Conversion
• Division method:
– Repeatedly divide by 2, remainder goes in next most
significant bit

Chapter 1 <14>
 Decimal To Binary Conversion
 Begin by dividing Decimal Number by 2. 15
 Then divide each resulting quotient by 2 until there is 0 whole-number
quotient.
 The remainders generated by each division form the binary number.
 Convert :
 Convert , , ,
Home Work
16
FROM ZERO TO ONE Number Conversion - Example
• Binary to decimal conversion:
– Convert 111012 to decimal

• Decimal to binary conversion:


– Convert 4710 to binary

Chapter 1 <17>
FROM ZERO TO ONE Number Conversion - Example
• Binary to decimal conversion:
– Convert 111012 to decimal
– 16×1 + 8×1 + 4×1 + 2×0 + 1×1 = 2910

• Decimal to binary conversion:


– Convert 4710 to binary
– Answer is 1011112

Chapter 1 <18>
Hexadecimal Numbers
19
 The hexadecimal number system has sixteen characters
 It is used primarily as a compact way of displaying or writing binary numbers
(Shorthand)
 long binary numbers are difficult to read and write
 Imagine writing a sixteen bit instruction for a microprocessor system in 1s and 0s.
 It is much more efficient to use hexadecimal or octal
 Hexadecimal is widely used in computer and microprocessor applications.
 Have you ever seen address of a variable?
 The hexadecimal number system has a base of sixteen
 Composed of 16 numeric and alphabetic characters.
 Most digital systems process binary data in groups that are multiples of four
bits
 Hexadecimal number very convenient because each hexadecimal digit represents a 4-
FROM ZERO TO ONE Hexadecimal Numbers
Hex Digit Decimal Equivalent Binary Equivalent
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15

Chapter 1 <20>
FROM ZERO TO ONE Hexadecimal Numbers
Hex Digit Decimal Equivalent Binary Equivalent
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111

Chapter 1 <21>
Binary-to-Hexadecimal Conversion
22
 Converting a binary number to hexadecimal is a straightforward procedure.
 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.

8 4 2 1
Hexadecimal-to-Binary Conversion
23
 To convert from a hexadecimal number to a binary number, reverse the
process and replace each hexadecimal symbol with the appropriate four bits.
24
Hexadecimal-to-Decimal & Vice
Versa Conversion

• Class Assignment 1
1. Convert the following hexadecimal numbers to decimal:
(a) 1C16 (b) A8516
2. Convert the decimal number 650 to hexadecimal
FROM ZERO TO ONE Bits, Bytes, Nibbles…
• Bits 10010110
– msb: most significant bit most least
significant significant
– lsb: least significant bit bit bit

byte

• Bytes & Nibbles 10010110


nibble
• Bytes
– MSB: most significant byte 1010001011100101
– LSB: least significant byte most least
significant significant
byte byte

Chapter 1 <25>
FROM ZERO TO ONE Bits, Bytes, Nibbles…
• Bits 10010110
– msb: most significant bit most least
significant significant
– lsb: least significant bit bit bit

byte

• Bytes & Nibbles 10010110


nibble
• Bytes
– MSB: most significant byte CEBF9AD7
– LSB: least significant byte
most least
– Each hex digit represents significant significant
a nibble (4 bits) byte byte

Chapter 1 <26>
27

BINARY ADDITION:
Binary BINARY SUBTRACTION:

Arithmetic SIGNED NUMBERS


Binary Arithmetic
 Binary Addition:
28
 The four basic rules for adding binary digits (bits) are as follows:

 In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written in the
given column and a carry of 1 over to the next column.
 Carry is left over bit
 When there is a carry of 1, you have a situation in which three bits are being added (a bit
in each of the two numbers and a carry bit).
29
FROM ZERO TO ONE Binary Addition Examples
• Add the following 1
1001
4-bit binary
+ 0101
numbers
1110

111
• Add the following 1011
4-bit binary + 0110
numbers 10001
Overflow!
Chapter 1 <30>
FROM ZERO TO ONE Overflow
• Digital systems operate on a fixed number of
bits
• Overflow: when result is too big to fit in the
available number of bits
• See previous example of 11 + 6
111
1011
+ 0110 Software Bug
The Ariane 5 Disaster
10001
Overflow!
Chapter 1 <31>
Binary Arithmetic
 Binary Subtraction:
32
 The four basic rules for subtracting bits are as follows:

 A borrow is required in binary only when you try to subtract a 1 from a 0.


 Subtract 011 from 101

33
34
Class Assignment 1

Solve the Above questions for practice, and disuses with me if needed
35
Signed Numbers

 Digital systems must be able to handle both positive & negative


numbers.
 A signed binary number consists of both sign & magnitude information.
 The sign indicates whether a number is positive or negative, & the
magnitude is the value of
 Two Ways :
1. Sign-magnitude
2. Complement (2’s)
Sign-Magnitude Form

36
The left-most bit in a signed binary number is the sign bit
 Sign Bit tells you whether the number is positive or negative.
A 0 sign bit indicates a positive number
A 1 sign bit indicates a negative number
 Decimal number +25 can be expressed as 8-bit signed binary
number using the sign-magnitude as: 16 8 1

 The decimal number -25 is expressed as


10011001
 Notice that the only difference between +25 and -25 is the sign bit because the magnitude
bits are in true binary for both positive and negative numbers.

Encode −4310 in Sign Magnitude Form ?


37
FROM ZERO TO ONE Complements of Binary Numbers

“Taking the Two’s Complement”


• Flips the sign of a number.
o It makes a positive number negative.
o It makes a negative number positive.
o Generally, applies on Negative numbers to make them positive
• Method:
1. Invert the bits
2. Add 1 to LSB

Chapter 1 <38>
FROM ZERO TO ONE “Taking the Two’s Complement”
• Flips the sign of a two’s complement
number.
• Method:
1. Invert the bits
2. Add 1
• Example: Flip the sign of 310 = 00112
1. 1100
2. + 1
1101 = -310

Chapter 1 <39>
FROM ZERO TO ONE Two’s Complement Examples
Take the two’s complement of 610 = 01102

Chapter 1 <40>
41
42

1010 0010
-0010 1101
+1
1110
1000

1010
+1110
1000
43

32 42 1
Subtraction Using Two’s Complement
1.First, find the 2's complement of the negative number. 44
2.Add both the numbers
If subtrahend larger
1.Find the 2's complement of the result.
2. Add a negative sign before the number so that we can identify that it
is a negative number(Only For when If subtrahend larger).
Example: 1101 and -1001
Example: 1101 and -1110
2's complement of number 2's complement of Number
0110+1=0111 0001+1=0010
Add 1101+0111=1 0100 Add 1101+0010= 1111

We discard the end-around carry. Only when Subtrahend is Larger


So, the addition of both numbers is Take 2's complement of the result
0100. and
45

Reading MANY SPECIALIZED CODES ARE USED


Assignment IN DIGITAL SYSTEMS.
1. BCD
2. GRAY
Digital Codes
Binary Coded Decimal (BCD) - 8421 46
 Binary coded decimal (BCD) is a way to express each of the decimal digits
with a 4-Bit binary code.
 it is very easy to convert between decimal & BCD.
 Expressing a Decimal number with binary could be cumbersome in case of
large decimal value But BCD codes are very handy.
 Large Decimal number can easily and quickly be represented in BCD Because each
decimal digit is treated separately and represented using 4bit binary number
 BCD code provides an excellent interface to binary systems.
 Examples of such interfaces are keypad inputs.
47
48

 Applications
 Digital clocks, digital thermometers, digital meters, and other devices with seven-
segment displays typically use BCD code to simplify the displaying of decimal
numbers.
 It is particularly useful if only limited processing is required, such as in a digital
thermometer.
Digital Device with Numeric Keypad

49
50
The Gray Code

 The Gray code is unweighted code


 No specific weights assigned to the bit positions.
 The important feature of the Gray code is that it exhibits only a single
bit change from one code word to the next in sequence.
 This property is important in many applications
 GrayCodes are used in position encoders, altimeters, and Karnaugh
maps due to their error detection and unit-distant properties.
 Table (Next Slide) is a listing of the 4-bit Gray code for decimal
numbers 0 through 15.
51
Binary-to-Gray Code Conversion
52
 The following rules explain how to convert from a binary number to a
Gray code word:
1. The most significant bit (left-most) in the Gray code is the same as the
corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits to get
the next Gray code bit and Discard carries. (aka X-OR operation)
 For example, the conversion of the binary number 10110 to Gray code is
as follows:
MSB LSB

Simply
bring it down
as it is
MSB

 The Gray code is 11101.


Gray-to-Binary Code Conversion
53
 To convert from Gray code to binary, The following rules apply:
1. The most significant bit (left-most) in the binary code is the
same as the corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit in the
next adjacent position. Discard carries.
 For example, the conversion of the Gray code word 11011 to
binary isMSB
as follows: LSB

Simply
bring it down
as it is

 The binary number is 10010.


54
55
Error Codes

 Common methods to detect an errors


1. The parity method
 Even Or Odd Parity
2. Cyclic redundancy Check
 Basic Concept:
 Adding extra bit(s) with data bits for detection

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy