0% found this document useful (0 votes)
19 views28 pages

Chapter 2

Uploaded by

masumatwoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views28 pages

Chapter 2

Uploaded by

masumatwoz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Learning Outcomes

 How numbers can be expressed in binary?


 Introduce a very compact way of representing binary
information.
 Hexadecimal number system
 Conversions between binary, decimal, and hexadecimal
numbers
 How negative numbers are represented?
 How characters are encoded and used by the computer?

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

Thousands Hundreds Tens Ones/Units

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

 Converting Binary and Hex to Decimal


 Consider the hex number 8A2D
8A2D.. It can be written as

 Similarly, the binary number 11101 may be written as

7
Conversion Between Number systems (1)
 An easier way is to use nested multiplication.

 Multiply the first hex digit by 16


16, and add the second
hex digit.
 Multiply that result by 16, and add the third hex digit
digit.
 Multiply the result by 16, add the next hex digit
digit, and so
on.

8
Exercises
 Convert 11101 to decimal.

 Convert 2BD4h 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)

 Conversions Between Hex and Binary


 To convert a hex number to binary, we need only express
each hex digit in binary
binary.
 Convert 2B3C
2B3Ch to binary.

 Binary to hex, just reverse this process;


process that is, group the
binary digits in fours starting from the right
right.

12
Addition and Subtraction
 Addition
 Consider the following decimal addition:

 An addition table for small hex numbers.


 To compute Bh + 9h, for example, just intersect the row
containing Bh and the column containing 9h, and read 14
14hh.

13
Hexadecimal Addition Table

14
Addition and Subtraction (2)
 Subtraction
 Let's begin with the decimal subtraction
Borrowing 1
left bit

 Hex subtraction may be done the same way as decimal


s11btraction.
15
Addition and Subtraction (3)

 Start with Fh - 4h = Bh.


 Borrow 1 from the third column. and compute
16h-9h=?
 9h + Dh = 16h, so 16h - 9h = Dh.
 12h - A - 1 =11 h - Ah = 7h
 Ch - Bh = 1.
16
Addition and Subtraction (4)
 Perform the subtraction on:
 5 F C 1 2h - 3 A B D 1 = ? (Answer is : 25041h)

 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

8-bits binary number: 01 10 0 001


One’s complement: 1001 1 1 1 0 shortcut 2s complement mile na check it

Two’s complement: + 1
1 0 0 1 1 1 1 1 = 9F (in Hex)
24
Subtraction as Two's Complement Addition

 The advantage of two's complement representation of


negative integers in the computer is that subtraction
can be done by bit complementation and addition
 Example: Suppose , AX contains 5ABCh and BX
contains 21FCh. Find the difference of AX minus BX by
using complementatio
complementation and addition
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

You might also like