0% found this document useful (0 votes)
24 views11 pages

Digital Lecture 02 - Number Systems and Codes 2

Uploaded by

bunajim
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)
24 views11 pages

Digital Lecture 02 - Number Systems and Codes 2

Uploaded by

bunajim
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
You are on page 1/ 11

ER1731 – Digital Electronics and Programmable Systems.

Digital Logic Systems 2 – Numbering Systems and Codes 2

Carl Berry
cberry1@uclan.ac.uk

Where opportunity creates success


2’s Complement Addition/Subtraction

Again to subtract we just add the negative.

Unsigned Binary Code Signed Binary Code

132 10000100 -124 10000100


+ 14 +00001110 + 14 +00001110
2’s Complement Addition/Subtraction
Examples
19 + 35
= 00010011 + 00100011
= 00110110 (54)
2’s Complement Addition/Subtraction
-19 + -35
So 19 = 00010011
therefore -19 = 11101100 + 1 = 11101101
And 35 = 00100011
therefore -35 = 11011100 + 1 = 11011101
Now 11101101 + 11011101 = 11001010 (ignore the final carry) gives us -54
Check it:
Subtract 1 = 11001001
Flip the bits = 00110110 gives us 54
Two to try at home +19 + 35 and -19 + 35 (contact me for help if you get stuck).
2’s Complement – Reaching the limits
76 + 67
= 01001100 + 01000011
= 10001111.
But anything starting with 1 is a negative value!
So what is it?
Subtract 1 and flip the bits gives 10001111 – 1 = 10001110 = 01110001 (113)
So 76 + 67 = -113?
There isn’t enough space in our word to store the real value (143).
With the last bit showing sign the highest value we can store is 01111111 (127)
The lowest value is 11111111 (-128)
The scale wraps around and starts counting 126, 127, -128, -127, -126…
We’ll see this in a future lab exercise.
BCD (8421 Code)
• There are other ways to store binary.
• One is Binary-Coded Decimal Code (BCD or sometimes 8421 encoding).
• Rather than encoding the entire number BCD encode each digit separately
• So 875 becomes :
• 1000 0111 0101 rather than a straight binary of 0011 0110 1011
• The advantages are that by coding each digit separately it’s much easier to convert from decimal.
• It also make floating point numbers easy.
• Disadvantages are that it takes up more memory space, each character must take up 4 bits. So a 3 digit
number will take up 12 bits regardless of actual magnitude.
• The circuitry and procedures for arithmetic are always more complex that the 2’s complement equivalent.
• There are a few different ways of dealing with negative numbers.
• Isn’t used much.
BCD (8421 Code) - Addition
An example:
58 + 69
= 0101 1000 + 0110 1001
Lets’s take 8 + 9 first.
1000 + 1001 = 10001
But this is 5 not 4 so what do we do?
We add 6.
?????????
In binary 4 bits can represent up to 16 (0-15) but in BCD we can only represent 10 digits (0-9).
10001 is the binary representation (16+1) so we need to make it into BCD, adding six carries this
representation into 8 bits of BCD, we do this if the number we have is bigger than 9 (here it’s 17).
So 10001 + 0110 gives 0001 0111 (17 in BCD)
BCD (8421 Code) - Addition
Next 5 + 6.
= 0101 + 0110
= 1011
Again this is the binary representation not the BCD and it’s over 9 so we have to add 6.
1011 + 0110
= 0001 0001 (11)
So the final BCD looks like 0001 0001 0001 0111
Hang on that’s four digits?????
Yes because the middle two are the units from the second sum and the carry from the first sum, so we add
them together.
0001 0010 0111 (127)
Like we said, more complex, not used much.
GRAY Code
• Unweighted code - used to represent a decimal value but the bit position is unweighted.

• Minimum-change code. Only one bit is different between consecutive codes. For example, only the LSB is
different between the Gray codes for 4 (0110) and 5 (0111).

• Not suitable in arithmetic operations.

• Mainly used in encoding position of devices such as angular positions of a motor shaft or the linear position
of a pen-recorder

• Position error will be minimum since there is only one bit change between consecutive codes. (Also called
minimum error code.)
GRAY Code
Decimal Binary Gray
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Encoding Standards

• There are a huge range of different encoding /


representation standards.
• They all have their own uses / advantages /
disadvantages.
• In any particular field or application there may
be a single standard that everyone adheres to or
there may be several possible competing
standards.
• This is not an uncommon situation in
Engineering / Technology.
• It is therefore important to know which you are
dealing with as the output can look very similar
(at first glance binary looks like GRAY, BCD etc.)
• We’ll meet another in the morning lectures in
the form of ASCII code.

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