Sunteți pe pagina 1din 6

In this lecture:

Lecture 2: Data Representation


• What do we mean by data?
• How can data be represented electronically?
Dr Pete Sedcole
Department of E&E Engineering • What number systems are usually used, and why?
Imperial College London • How do number systems in different bases work?
http://cas.ee.ic.ac.uk/~nps/
• How do you convert a number from decimal to binary
and binary to decimal?
(Floyd 2.1 – 2.4, 2.8, 2.10 – 2.11)
(Tocci 2.1 – 2.8)

E1.2 Digital Electronics 1 2.1 16 October 2008 E1.2 Digital Electronics 1 2.2 16 October 2008

What do we mean by data? Electronic representation of data


• Information can be complex
• It depends on context, but we will say: – e.g.: numbers, music, pictures
data = physical representation of information
• Data can be stored • What can we do using electronics?
– e.g.: computer disk, DVD, SIM card – Set up voltages and currents
– Change voltages and currents 5 Volts
• Data can be transmitted
– e.g.: fax, text message R
• A useful device is a switch
• Data can be processed
– closed: V = 0 Volts
– e.g.: cash till – open: V = 5 Volts Switch V

E1.2 Digital Electronics 1 2.3 16 October 2008 E1.2 Digital Electronics 1 2.4 16 October 2008
• We can represent information using voltage levels Number systems
• The simplest information is TRUE/FALSE
– This can be represented by two voltage levels:
Hexadecimal
• 5 Volts = TRUE
(base 16)
• 0 Volts = FALSE
• A unit of information that has only two possible values is
also called a BIT (short for Binary Digit)
Decimal Binary
• Why do we use binary data in electronics? (base 10) (base 2)
– Simple to implement in hardware: we only need
switches
– Good tolerance to noise Octal
(base 8)

E1.2 Digital Electronics 1 2.5 16 October 2008 E1.2 Digital Electronics 1 2.6 16 October 2008

Decimal numbers Binary numbers


• Deci = ten
• The decimal number system has ten digits: • Bi = two
0, 1, 2, 3, 4, 5, 6, 7, 8, 9. • The binary number system has two digits:
• The decimal number system has a base of 10, with 0 and 1.
each digit position weighted by a power of 10: • The binary number system has a base of 2 with each
s

digit position weighted by a power of 2:


s
dth
tho dths
ds

d th
s

an
red
an

an
re
ths

us
us

nd

-
nd

es

us
ten
s
tho

ten
ten

hu
hu

on

tho

MSD = most 23 22 21 20 ∏ 2-1 2-2 2-3 2-4 MSB = most


103 102 101 100 ∏ 10-1 10-2 10-3 10-4 significant digit significant bit
MSB LSB
MSD LSD LSD = least LSB = least
significant digit binary point significant bit
decimal point
E1.2 Digital Electronics 1 2.7 16 October 2008 E1.2 Digital Electronics 1 2.8 16 October 2008
Binary number system Integers and fractions in binary
• Binary numbers can represent fractional values as well
as integers
• A binary number uses the digits 0 and 1
– e.g.: 10011.0112 24 23 22 21 20 2-1 2-2 2-3
• Subscript 2 indicates the number is in binary notation
(base 2) 1 0 0 1 1 ∏ 0 1 1
= (19.375)10
• Example: 100112 is: 24 23 22 21 20

1 0 0 1 1 • 10011.0112 is an 8-bit number


• It is in Q3 format – it has 3 bits after the binary point
1 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 19
• What if we want to represent (19.376)10 with an 8-bit
binary number?

E1.2 Digital Electronics 1 2.9 16 October 2008 E1.2 Digital Electronics 1 2.10 16 October 2008

Conversion: decimal to binary (method 1) Conversion: decimal to binary (method 2)

• Express the decimal number as the sum of powers of 2 • Repeated division


• 1s and 0s written in the corresponding bit positions
quotient remainder

Example 1: Example 2: 50/2 = 25 0 LSB

5010 = 32 + 18 338.510 = 256 + 82.5 25/2 = 12 1

= 32 + 16 + 2 = 256 + 64 + 18.5 12/2 = 6 0

= 1x25 + 1x24 + 1x21 = 256 + 64 + 16 + 2.5 6/2 = 3 0

5010 = 1100102 = 256 + 64 + 16 + 2 + 0.5 3/2 = 1 1

= 1x28 + 1x26 + 1x24 + 1x21 + 1x2-1 1/2 = 0 1 MSB

338.510 = 101010010.12 5010 = 1100102

E1.2 Digital Electronics 1 2.11 16 October 2008 E1.2 Digital Electronics 1 2.12 16 October 2008
Conversion: binary to decimal Binary addition
1 1

A 1 2 5 4
• Determine the power of 2 for the position of each 1, and • Firstly, recall decimal addition:
+B 7 8 2
then sum Sum 2 0 3 6

• Example: • Binary addition follows the same pattern, but


(10101)2 = 24 + 22 + 20 = 16 + 4 + 1 = (21)10 0+0 = 0 carry 0
1 1
0 + 1 = 1 + 0 = 1 carry 0
1+1 = 0 carry 1 A 0 1 1 1
• Not the only way to do it… 1+1+1 = 1 carry 1 +B 0 1 1 0
Sum 1 1 0 1

E1.2 Digital Electronics 1 2.13 16 October 2008 E1.2 Digital Electronics 1 2.14 16 October 2008

Hexadecimal numbers
Binary addition
• Hexadeci = sixteen
• Note that to calculate each bit sn of the sum, we need to • Base 16 representation
consider the values of 3 input bits:
• Easy to convert to and
– The corresponding bits of A and B, (an and bn) from binary numbers
– The carry-out from the previous addition • More compact to write,
easier for us to read than
binary
• Each bit or column of the binary addition generates two
outputs
– sum sn and carry-out

E1.2 Digital Electronics 1 2.15 16 October 2008 E1.2 Digital Electronics 1 2.16 16 October 2008
Hexadecimal number conversions Binary Coded Decimal (BCD)

• Binary-to-hexadecimal
• Use 4-bit binary to represent one decimal digit
1. Separate the binary number into 4-bit groups
• Easy to convert between decimal ↔ binary
2. Replace each group with the hexadecimal equivalent
• Wastes bits (4 bits can represent 16 values, but only 10
• Hexadecimal-to-decimal values are used)
1. Re-write each hexadecimal digit as the 4-bit binary equivalent • Used extensively in financial calculations
2. Convert the binary number to decimal

• Decimal-to-hexadecimal
– Repeated division by 16

E1.2 Digital Electronics 1 2.17 16 October 2008 E1.2 Digital Electronics 1 2.18 16 October 2008

Putting it all together


Binary Coded Decimal (BCD)

• Convert 0110100100010111 (BCD) to its decimal equivalent:


0110 1001 0001 0111
6 9 1 7

• Convert the BCD number 011111000001 to decimal


0111 1100 0001
7 ? 1

The forbidden code group indicates an error has occurred

E1.2 Digital Electronics 1 2.19 16 October 2008 E1.2 Digital Electronics 1 2.20 16 October 2008
Gray Codes • Binary code results in glitches
• Gray code avoids glitches

• Only one bit in the code


changes in the sequence

• Useful for industrial control

E1.2 Digital Electronics 1 2.21 16 October 2008 E1.2 Digital Electronics 1 2.22 16 October 2008

ASCII code
• Codes representing letters
of the alphabet,
punctuation marks and
other special characters
are called
alphanumeric codes
• The most widely used
alphanumeric code is the
American Standard Code
for Information
Interchange, or ASCII
• ASCII is pronounced
“askee”
• It is a 7-bit code
E1.2 Digital Electronics 1 2.23 16 October 2008

S-ar putea să vă placă și