EEE 204 - Lecture2
EEE 204 - Lecture2
2021
Chapter 2
Number Systems and Data Formats
Computers and digital systems understand logic 1 and 0 and process the
information that consists of them.
Nibble: 4-bit-width
• Byte: 8-bit width
• Word: 16-bit width
• Double word: 32-bit width
• Quad: 64-bit width
These lengths are associated to usual hardware. In the MSP430, for example,
registers are 16 bits wide. Notice the specific use of the term “word” for 16 bits.
Individual bits in a word are named after their position, starting from the right
with 0: bit 0 (b0), bit 1 (b1), and so on. Symbolically, an n-bit word is denoted as
eeee 1
24.02.2021
The rightmost bit, b0, is the least significant bit (lsb), while the leftmost one,
bn−1, is the most significant bit (msb).
eeee 2
24.02.2021
Number Systems
In this section we will talk about the most common conventions, starting with the
normal binary notation, which is a positional numerical system.
Our decimal system is positional, which means that any number is expressed by
a permutation of digits and can be expanded as a weighted sum of powers of ten,
the base of the system. Each digit contributes to the sum according to its position
in the string. Thus, for example,
eeee 3
24.02.2021
Numbers are written as a sequence of digits and a point, called radix point, which
separates the integer from the fractional part of the number to the left and right side
of the point, respectively.
Here, each subscript stands for the exponent of the weight associated to the digit
in the sum. The leftmost digit is referred to as the most significant digit (MSB) and
the rightmost one is the least significant digit (LSB). If there were no fractional part
in equation the radix point would be omitted and the number would be called
simply an integer. If it has no integer part, it is customary to include a “0” as the
integer part. The number denoted by the equation represents a power series in r of
the form
eeee 4
24.02.2021
The power expansion of a number may be used to convert from one base to
another, performing the right hand side operations in the target system.
Notice that for hexadecimal conversion, all hex digits are interpreted in their
decimal values for the sum.
eeee 5
24.02.2021
power of base 2 increases to the right for integer part and decreases to the left for
fractional part
Integer Conversion
One popular procedure for converting decimal integers into base r is the repeated
division method. This method is based on the division algorithm, and consists in
successively dividing the number and quotients by the target radix r until the quotient
is 0. The successive remainders of the divisions are the digits of the number in base r ,
starting from the least significant digit: divide the number by r and take the remainder
as a0; divide the quotient by r , and the remainder as a1, and so on. Let us illustrate
with a pair of examples.
eeee 6
24.02.2021
Fractional Part
eeee 7
24.02.2021
eeee 8
24.02.2021
Example:
Convert (376.9375)10 to base 2. First convert the integer part by successive
divisions by 8:
Division Quotient Remainder
376/2 188 0
188/2 94 0
94/2 47 0
47/2 23 1
23/2 11 1
11/2 5 1
5/2 2 1
2/2 1 0
1/2 0 1
eeee 9
24.02.2021
0.75x2 1.5 1
0.5x2 1 1
(376.9375)10 =(101111000.111)
The lower the base, the more digits required to represent a number. The binary
numerical system, the ‘natural’ one for digital systems, is quite inconvenient for
people.
Associate each hex digit to four binary digits, from right to left in the integer part and
from left to right in the fractional part.
eeee 10
24.02.2021
there is a one to one correspondence between each hex digit and a group of four
bits, a nibble.
Base 16 number system or hexadecimal number system has been universally adopted
in the embedded systems literature as well as in debuggers. Thus, memory addresses,
register contents, and pretty much everything else are expressed in hexadecimal
integers without implying that they are a number.
eeee 11
24.02.2021
Addition
0+0=0
0 + 1 =1 + 0 = 1
1 + 1 = 10
Example:
Example:
Add these decimal numbers to each others in binary numbering system
152.75 and 236.375
152.75 = 10011000.11B
236.375 = 11101100.011B
eeee 12
24.02.2021
Subtraction
Subtraction follows the usual rules too. When the minuend digit is less than the
subtrahend digit, a borrow should be taken. For subtraction, the rules are
When a borrow is needed, it is taken from the next more significant digit of the
minuend, from which the borrow should be subtracted. Hence, actual subtraction
can be considered to be carried out using three digits: the minuend, the subtrahend,
and the borrowed digit.
Example: Subtract 231 from 325 using binary subtraction.
1 0 1 0 0 0 1 0 1 = 325
- 0 1 1 1 0 0 1 1 1 =231
0 1 0 1 1 1 1 0 =94
13710001001
011101101’s complement
1
+
01110111 2’s complement of 137
Since the answer has a carry (9 bits), the
result is positive. Dropping this carry, we have
11011000
the solution to this subtraction 01001111B =
+ 01110111 79.
carry 101001111 drop carry then =0x4F=(79)10
Introduction to Embedded Systems University of Gaziantep
EEE204 Prof. Dr. Ergun Erçelebi Department of EEE
eeee 13
24.02.2021
0111 1101
+ 0001 1000
10010101
Since the sum does not yield a carry (8 bits), the result is negative, with an absolute.
To find its decimal equivalent we take 2’ complement.
eeee 14
24.02.2021
Sixteen’s Complement: find the difference for each hex digit with respect to F and
then add 1 to the result.
Example: A set of data for bytes and words is given in hex notation as
0×7A, 0×9F24, 91H and CFA20h Find the two’s complement of each one using
hex notation and verify the response in binary.
Numbers can be real valued or integer valued. Real-valued numbers can have fractions.
But integer-valued numbers don't have fractions. Besides, numbers can be defined as
signed or unsigned in embedded systems.
eeee 15
24.02.2021
QUESTIONSS
eeee 16