You are on page 1of 28

Department of Electrical

Engineering

Embedded Systems

Information Representation in
Embedded Systems

Lecture 2

Dr F Bensaali

Content:
Numbers
Unsigned integers

Signed integers
Fixed-point
Floating-point

Text
The American Standard Code for Information Interchange (ASCII)
code

Signed vs Unsigned binary representations

With decimal numbers we have a sign to distinguish positive to


negative numbers
o e.g. -5 and +5 represent negative 5 and positive 5 where and +
are the signs

In binary number representations similar rules follow where a


sign bit is typically used to represent negative numbers
o Often most significant bit is used to indicate whether the binary
number is positive or negative. The remaining bits in the number
indicate the magnitude

In most cases it is specified whether the number is signed


(negative) or unsigned (positive)
o e.g. the signed binary number 1001 represents -1 in decimal
the unsigned binary number 1001 represents 9 in decimal

1s and 2s complements of binary numbers


1s and 2s complement of a binary number are used to
represent negative numbers
o 2s complement representation is commonly used in computers
and digital systems to handle negative numbers
1s complement
The 1s complement of a binary number is found by changing all 1s
to 0s and all 0s to 1s
2s complement
The 2s complement of a binary number is found by adding 1 to the
LSB of the 1s complement
2's complement = (1's complement) + 1
4

1s and 2s complements of binary numbers (Contd)


Example
Find the 2s complement of 01011011
Solution
01011011
10100100
+
1

Binary number (9110)


1's complement
Add 1

10100101

2's complement (-9110)

Addition
The two numbers in an addition are addend and the augend.
The result is the sum

Four cases can occur when adding two signed binary numbers:
Both numbers positive
Positive number with magnitude larger than negative number
Negative number with magnitude larger than positive number
Both numbers negative

Addition - examples
Using 8-bit signed numbers:
Both numbers positive
00001001

+ 00000111

+ 7

00010000

16

Positive number with magnitude


larger than negative number

Discard
the carry

The sum is positive and therefore


in true binary

Negative number with magnitude


larger than positive number
00001111

15

+ 11100111

+ -25

11110110

-10

The sum is negative and


therefore in 2's complement form

00001010

10

+ 11111010

+ -6

100000100
4
The sum is positive and therefore
in true binary

Both numbers negative

Discard
the carry

11111011

-5

+ 11111010

+ -6

111110101
-11
The sum is negative and
therefore in 2's complement form
7

Addition Overflow condition


If the number of bits required to represent the sum exceeds the
number of bits in the addend and the augend, an overflow
results as indicated by an incorrect sign bit
01111000
+ 00111100
10110100

120
+

60
180

Sign incorrect
magnitude incorrect

An overflow can occur only when both numbers are positive or


both are negative

Subtraction
Subtraction is a special case of addition
Subtracting y (the subtrahend) form x (the minuend) is equivalent
to adding y to x
The signed of a positive or negative binary number is changed by
taking its 2s complement

Subtraction is addition with the sign of the subtrahend changed.


The result is called the difference
Exercise

Perform each of the following subtractions of the signed


numbers:
a. 00001001 00000100
b. 00001100 11110111
9

Multiplication
This is similar to multiplication of decimal numbers
Each bit in the multiplier is multiplied by the multiplicand to get
the corresponding partial product
Step 1

Step 2

Determine the sign of the product from the sign of the multiplicand and multiplier
Change any negative number to true form (uncomplemented)

Starting with the list significant multiplier bit, generate the partial products. Shift each
successive partial product one bit to the left
Step 3
Step 4
Step 5

Add each successive partial product to the sum of the previous partial products
If the sign determined in step 1 is negative, take the 2s complement of the product

10

Multiplication (Contd)
Example

Multiply the signed binary numbers: 01010011 (multiplicand) 10111011


(multiplier)
Step 1: The sign bit of the product will
be 1(negative)
Step 2: 2s complement of the
multiplier to put it in the true form:
01000101
Step 3 & 4:

Step 5: Since the sign of the product is


1, take the 2s complement of the
product. So the final result is:
110100110100001

01010011
x 01000101
01010011
+ 00000000
001010011
+ 01010011
0110011111
+ 00000000
00110011111
+ 00000000
000110011111
+ 00000000
0000110011111
+ 01010011
01011001011111
+ 00000000
001011001011111

Multiplicand
Multiplier
1st partial product
2nd partial product
sum
3rd partial product
sum
4th partial product
sum
5th partial product
sum
6th partial product
sum
7th partial product
sum
8th partial product
final product
11

Fixed-point representation
There are a number of ways that non-integers (real numbers)
can be represented
Fixed-point and Floating-Point representations are the most
commonly used ways
o Floating-point representation is more accurate than fixed-point
representation
o Fixed point data type is used widely in digital signal processing
(DSP), where performance is sometimes more important than
precision

12

Fixed-point representation (Contd)

110112 = 2710
if we divide the number 27 by 2,
we know the result should be
13.5

How do we represent it
if we only had integer
representations?

Binary point concept is the key to represent fractional numbers,


like 13.5
o It is like the decimal point in a decimal system

o It acts as a divider between the integer and the fractional parts of a


number
13

Fixed-point representation (Contd)

Power
Base
Digits

1
10
1

0
10
3

-1
10
5

Total units:
(1x101)+(3x100)+(5x10-1)
DECIMAL number:

13.510

The same concept of decimal point can be applied to the binary


representation, making a binary point
14

Fixed-point representation (Contd)


All bits to the left of the binary point carry a weight (power) of 20,
21, 22 and so on

Bits on the right of binary point carry a weight (power) of 2-1, 2-2,
2-3 and so on

1101.12

Power
Base
Digits

3
2
1

2
2
1

1
2
0

0
2
1

-1
2
1

Total units:
(1x23)+(1x22)+ (0x21)+(1x20)+(1x2-1)
Binary number: 1101.12 = 13.510
15

Fixed-point representation (Contd)


Exercise
Compare the bit pattern of 27 and 13.5
What do you notice?

16

Fixed-point representation (Contd)


To define a fixed-point type conceptually, we need two
parameters:
Width of the integer part, and
Width of the fractional part
Integer part
(m bits)

...

Fractional part
(n bits)

...
+2-n
+2-3=0.125
+2-2=0.25
+2-1=0.5
17

Fixed-point representation (Contd)


Conversion of fractional part to binary
Multiply the fractional part successively by 2 and
note the integer part of product
Step 1
Repeat the process till the fractional part
becomes 0
Step 2
Binary equivalent of the fractional part are the
integer parts of the products
Step 3

Example
0.7510 = ?
0.75 x 2 = 1.5
0.5 x 2 = 1.0 (fractional part =0)
0.7510 = 0.112

Fixed-point representation (Contd)


Exercise
In a digital hardware, numbers are represented using fixed-point
format with 8 bits and 4 bits for integer and fractional parts
respectively.
Given 53.62510, determine the equivalent number in binary.

19

Fixed-point representation (Contd)


Solution
Integer part (8 bits)

Fractional part (4 bits)

53.62510 = ?2

20

Fixed-point representation (Contd)


Negative fixed-point numbers can be represented by applying
the twos complement representation to the integer part
Exercise
In a digital hardware, numbers are represented using fixed-point
format with 8 bits and 6 bits for integer and fractional parts
respectively.
Given -8.687510, determine the equivalent number in binary.

21

Fixed-point representation (Contd)


Solution
Integer part (8 bits)

Fractional part (6 bits)

-8.687510 = ?2
22

Floating-point binary representation


Almost 25 years ago the IEEE 754 binary floating-point standard
was adopted
o Since then almost every processor as well as many programming
languages have defined the floating-point arithmetic to be
IEEE754 compliant
o The IEEE standard has four different precision formats: single,
single extended, double and double extended
o The single and double precision formats are the most commonly
used

23

Floating-point binary representation (Contd)


Using IEEE floating-point representation, any real number is
decomposed into:
sign (s)
mantissa (m)
exponent (e)
Single precision (32 bits)

Double precision (64 bits)

= () .
x31

sign

x30

x23 x22

exponent (8 bits)

= () .
x0

mantissa (23 bits)

x63 x62

sign

x52 x51

exponent (11 bits)

x0

mantissa (52 bits)

24

Floating-point binary representation (Contd)


Example
= 10000000 00110000000000000000000
0

10000000

00110000000000000000000

=
e= 10000000=128 10
m=00110000000000000000000= + = .
= () . = () .
= . = .
25

Text
The American Standard Code for Information Interchange (ASCII)
code is a binary code in which 7-bit vectors are used to represent:
Alphabetic characters;
Numeric characters; and

Symbolic characters

The standard was originally designed to include control


characters meant to manage peripherals such as printers

26

Text (Contd)
Hexadecimal to ASCII text conversions

The entire first


column contains
all of the control
characters.

27

Text (Contd)
More recent versions of the code include extended ASCII
o It uses the 8th bit in the standard byte to include 128 other
characters

Extended ASCII Codes

28

You might also like