Chapter 2
Chapter 2
2
Number systems
Decimal system /Positional number system
Each digit in the number is associated with a power of
10, according to its position in the number
3
Number systems (1)
Binary Number System
The base is two and there are only two digits, 0 and 1.
The binary string 11010 represents the number:
4
Number systems (2)
Hexadecimal Number System
Numbers written in binary tend to be long and difficult
to express.
16 bits are needed to represent the contents of a memory
word in an 8086
8086-based computer.
Assembly language programs tend to use both binary,
decimal, and a third number system
Hexadecimal
Conversion between binary and hex is easy
5
Number systems (3)
A base sixteen system.
Digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
Each hex digit corresponds to a unique four
four--bit number.
6
Conversion Between Number systems
7
Conversion Between Number systems (1)
An easier way is to use nested multiplication.
8
Exercises
Convert 11101 to decimal.
9
Conversion Between Number systems (2)
Converting Decimal to Binary and Hex
Convert 11172 to hex
4
16 11172
16 698 10 = A
16 43 11 = B
2
The answer 2BA4h
10
Conversion Between Number systems (3)
Convert 95 to binary.
Divide the number by 2
Oder the remainders from MSB to LSB
The answer is 95 = 1011111
1011111b.
11
Conversion Between Number systems (4)
12
Addition and Subtraction
Addition
Consider the following decimal addition:
13
Hexadecimal Addition Table
14
Addition and Subtraction (2)
Subtraction
Let's begin with the decimal subtraction
Borrowing 1
left bit
F001E-1FF3F=?
(Answer is : D00DF h)
17
Unsigned Integers
An unsigned integer is an integer that represents a
magnitude, so it is never negative.
magnitude
addresses of memory locations, counters, and ASCII
character codes
None of the bits are needed to represent the sign
The largest unsigned integer that can be stored in a
byte is 11111111 = FFh = 255.
The biggest unsigned integer a 16 bit word can hold is
1111111111111111 = FFFFh =65535.
18
Signed Integers
A signed integer can be positive or negative
negative.
The most significant bit is reserved for the sign
sign:
1 means negative and 0 means positive.
Negative integers are stored in a computer in a special
way known as two's complement
complement.
One's Complement
an integer is obtained by complementing each bit; that
is, replace each 0 by a 1 and each 1 by a 0.
19
Signed Integers (2)
Find the one's complement of 5.
Converting to 16 bits binary, 00000000
0000000000000101
00000101
5 = 00000000
0000000000000101
00000101
One's complement of 5 = 111l111111111010
Find the one's complement of 18.
Converting to 16 bits binary, 0000000000010010
One's complement of 18 = 1111111111101101
20
Signed Integers (3)
Two's Complement
To get the two's complement of an integer, just add 1 to
its one's complement
complement.
Find the two's complement of 5.
21
Signed Integers (4)
Let’s have a look what happens when add 5 and two’s
complement of it.
Discard 1, as
computer circuit
contains 16 bits The two's complement of 5 must
only be a correct representation of -5.
22
Signed Integers (5)
Find the two's complement of the two's complement of
5.
23
Signed Integers (6)
Show how the decimal integer -97 would be
represented (a) in 8 bits
bits, and (b) in 16 bits
bits. Express the
answers in hex.
(a) 8 bits representation of -97
1. Convert 97 to binary, 110 0001
2. Adding 0 to the leftmost bit to make it 8 bits (0 110 0001)
3. Applying two’s complement on 8 bit binary number of 97
Two’s complement: + 1
1 0 0 1 1 1 1 1 = 9F (in Hex)
24
Subtraction as Two's Complement Addition
25
Character Representation
Not all data processed by the computer are treated as
numbers
the video monitor and printer are character oriented
Characters must be coded in binary in order to be
processed by the computer.
ASCII code
This system uses seven bits to code each character, so
there are a total of 27= 128 ASCII codes.
Only 95 ASCII codes, from 32 to 126 126, are considered to
be printable.
26
Character Representation (2)
The codes 0 to 31 and also 127 were used for
communication control purposes and do not produce
printable characters.
the control characters are used to control the
operations of these devices.
27
28