0% found this document useful (0 votes)
9 views

Digital Lecture 01 - Number Systems and Codes

Uploaded by

bunajim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Digital Lecture 01 - Number Systems and Codes

Uploaded by

bunajim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

ER1731 – Digital Electronics and Programmable Systems.

Digital Logic Systems 1 – Numbering Systems and Codes

Carl Berry
[email protected]

Where opportunity creates success


Number Systems

• Most of the number systems we as humans use are based on 10 (not all of them, time for instance).
• Computers use a number of representations, the most common number systems are :
– Binary (Base 2). (0,1)
– Decimal (Base 10). (0,1,2,3,4,5,6,7,8,9)
– Hexadecimal (Hex) (Base 16). (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
– Octal (Base 8) is used to a lesser extent in certain areas.

• A number system uses the symbols as digits.

• The value of a digit depends on its position.

• The above are positional-value number systems.


Number Systems

• If you remember back to when you first started doing Maths you probably used something like:
• Thousands(1000) Hundreds(100) Tens(10) Units(1)
• Or 103 102 101 100
• So 6532 is 6 thousands, 5 hundreds, 3 tens and 2 units.
• The other number systems work the same way, it’s just that the headings are different.
• For Binary it’s (from least significant) 20, 21, 22 etc. or 1, 2, 4, 8, 16, 32 etc.
• So a binary number 101101 is 1 unit, 0 twos, 1 four, 1 eight, 0 sixteens and 1 thirty two.
• 1+0+4+8+0+32 = 45 in decimal.
• It is obviously useful to be able to convert between number systems.
Number Systems – Converting Binary to Hex.
Converting large groups at once can be tricky and confusing but here we can split them up to make it easier.

Convert groups of 4 digits directly to hex, starting from the least significant digit up :

0011110101102 = 0011 / 1101 / 01102 = 3D616

Try these :

1110111110102 =

11001100100112 =
Number Systems – Converting Hex to Binary.
And we can go back the other way.

Convert each hex digit to the 4-bit binary code :-

8A216 = 1000 / 1010 / 00102 = 1000101000102

Try these:

5A516 =

FED16 =
Number Systems – Converting Hex to Decimal.
Of course we still largely think in decimal so…

Convert each hex digit to the 4-bit binary code :-

8A216 = 8 x 162 + 10 x 161 + 2 x 160

= 8 x 256 + 10 x 16 + 2x1

= 2048 + 160 + 2

= 221010
Number Systems – Converting Decimal to Hex.
The reverse this time is a bit trickier.

The positional weight of each hex number is :-

164 163 162 161 160

65536, 4096, 256, 16, 1

So we’re going to have to do some successive divisions (we’ll see how we can use % for this in C in a few
weeks).

29910 = 0 + 0 + 256 + 32 + 11 = 12B16

Try this:

60010 =
Number Systems – Converting Binary to Decimal.
101101102 = 27 + 25 + 24 + 22 + 21
= 128 + 32 + 16 + 4 + 2 = 18210

Try These:

011010112 =

111111112 =
Number Systems – Converting Decimal to Binary.
Again going the other way can be a bit trickier (at least until you get used to it)

3810 = 32x1 + 16x0 + 8x0 + 4x1 + 2x1 + 1x0


= 1 0 0 1 1 0
= 1001102

Try these:

• 8910 =

• 10510 =
Number Systems – Hex can help!
• Weirdly (?) it can be easier to use Hex as a halfway step in Binary and Decimal conversions.

• Remember how easy it was to go from Hex to Binary and Binary to Hex.

011010102 = 0110 / 1010 = 6 / A = 6A16

6x16 + 10 = 96 + 10 = 10610

Try these:

001111012 =

1011001100112 =
Number Systems – Addition.
• Addition in binary works in exactly the same way as it does in decimal (and indeed any other number
base).
• We start at the least significant digit and if an addition causes an overflow we carry terms upwards.
• In decimal if an addition causes > 9 then we carry a 1 to the next column (assuming it is less than 20).
• In binary we carry a 1 if the sum produces a value > 1:

0 + 0 = 0 (no carry)
1 + 0 = 1 (no carry)
0 + 1 = 1 (no carry)
1 + 1 = 0 (1 to carry)

Example :

10110101
+ 01101101

Addition is the most important operation in computer systems and is the basis for other operations
(subtraction, multiplication, division etc.)
Number Systems – Signed Binary Numbers.
• We need to know if a value is positive or negative .
• In binary we use the most significant digit as the sign if the number is signed.
• So in an 8 bit system (8 bit word)
• Unsigned range would be 00000000 = 0 to 11111111 = 255
• Signed range would be 11111111 = -128 to 01111111 = +127

• There are three methods for representing signed binary.


• Sign and Magnitude.
• 1’s Complement.
• 2’s Complement.
Number Systems – Signed Binary Numbers.
• Sign and Magnitude: the MSB is the sign bit and the lower bits represent the magnitude.
Example:
+119 = 01110111.
Try These (for an 8 bit word):
-119 =
12 =
230 =
Number Systems – Signed Binary Numbers.
• 1’s complement: the negative number is derived by inverting each bit of the magnitude equivalent positive
number.
Example
+119 = 01110111
-119 = 10001000

Try These:
+12 =
-12 =
Number Systems – Signed Binary Numbers.
• 2’s complement: the negative number is formed by adding 1 to the 1’s complement form of the number.
Example:
+119 = 01110111
-119 = 10001001

Try these

+12 =
-12 =
Number Systems – Signed Binary Numbers.
• Why do we need more than one system?
• Most computers use the 2’s complement for signed numbers.
• 2’s complement allows subtraction to be performed using addition. A digital computer can therefore use
the same adder circuitry for both add and subtract.
• The signed magnitude and 1’s complement form require more complex circuits. Also they have two codes
for zero.
• 0 signed magnitude (8 bit) can be 00000000 but so is 10000000
• Same for 1’s complement.
• 0 for 2’s complement is 00000000.

You might also like