This document discusses representation of numbers and characters in computers. It covers:
1) Computers only use binary to represent all data as 0s and 1s. This includes numbers, letters, and other characters.
2) Different numbering systems are characterized by their base, such as binary (base 2), decimal (base 10), and hexadecimal (base 16). Conversions between these systems are explained.
3) Binary numbers represent values as sums of powers of 2. Hexadecimal combines 4 binary bits into single hexadecimal digits to compactly represent numbers.
2. Our Group Members are:
Name Id
Mohammad Obaedul Islam 4080
Shaikh Kamrul Islam 3814
Debashish Mondal 3709
Ashraful Alam Sabbir 4086
3. Outline
• Introduction
• Numbering Systems
• Binary & Hexadecimal Numbers
• Binary and Hexadecimal Addition
• Binary and Hexadecimal subtraction
• Base Conversions
4. Introduction
• Computers only deal with binary data (0s and 1s), hence all
data manipulated by computers must be represented in
binary format.
• Machine instructions manipulate many different forms of
data:
– Numbers:
• Integers: 33, +128, -2827
• Real numbers: 1.33, +9.55609, -6.76E12, +4.33E-03
– Alphanumeric characters (letters, numbers, signs, control
characters): examples: A, a, c, 1 ,3, ", +, Ctrl, Shift, etc.
• So in general we have two major data types that need to be
represented in computers; numbers and characters
5. Number System
• Numbering systems are characterized by their base
number.
• In general a numbering system with a base r will have r
different digits (including the 0) in its number set. These
digits will range from 0 to r-1
• The most widely used numbering systems are listed in
the table below:
7. Binary Numbers
• Each digit (bit) is either 1 or 0
• Each bit represents a power of 2
• Every binary number is a sum of powers of 2
Binary 10101001 = decimal 169
Conversion :(1 27) + (1 25) + (1 23) + (1 20)
= 128+32+8+1=169
1 1 1 1 1 1 1 1
27 26 25 24 23 22 21 20
8. Converting from Decimal fractions to Binary:
• Converting 0.8125 to binary . . .
– Ignoring the value in the units
place at each step, continue
multiplying each fractional part
by the radix.
– You are finished when the
product is zero, or until you have
reached the desired number of
binary places.
– Our result, reading from top to
bottom is:
0.812510 = 0.11012
– This method also works with any
base. Just use the target radix as
the multiplier.
9. Hexadecimal Integers
• Each hexadecimal digit corresponds to 4 binary bits.
• Example: Translate the binary integer
000101101010011110010100 to hexadecimal
Binary values are represented in hexadecimal.
Converting Binary to Hexadecimal
10. • Multiply each digit by its corresponding power of 16:
• Examples:
– Hex 1234 = (1 163) + (2 162) + (3 161) + (4 160) =
Decimal 4,660
– Hex 3BA4 = (3 163) + (11 * 162) + (10 161) + (4 160) =
Decimal 15,268
Converting Hexadecimal to
Decimal
Converting Hexadecimal to
Binary• Each Hexadecimal digit can be replaced by its 4-bit binary
number to form the binary equivalent.
11. Binary Addition
• Start with the least significant bit (rightmost bit)
• Add each pair of bits
• Include the carry in the addition, if present
0 0 0 0 0 1 1 1
0 0 0 0 0 1 0 0
+
0 0 0 0 1 0 1 1
1
(4)
(7)
(11)
carry:
01234bit position: 567
12. Hexadecimal Addition
• Divide the sum of two digits by the number base (16). The quotient
becomes the carry value, and the remainder is the sum digit.
36 28 28 6A
42 45 58 4B
78 6D 80 B5
11
21 / 16 = 1, remainder 5
Important skill: Programmers frequently add and subtract the addresses
of variables and instructions.
13. Binary Subtraction
• Rules of Binary Subtraction
0 - 0 = 0
0 - 1 = 1, and borrow 1 from the next more significant bit
1 - 0 = 1
1 - 1 = 0
• For example,
00100101- 00010001=00010100 0 borrows
0 0 1 10 0 1 0 1 = 37(base 10)
- 0 0 0 1 0 0 0 1 = 17(base 10)
0 0 0 1 0 1 0 0 = 20(base 10)
14. When a borrow is required from the digit to the left,
add 16 (decimal) to the current digit's value
Hexadecimal Subtraction
C675
A247
242E
-1
-
16 + 5 = 21
C675
5DB9 (2's complement)
242E (same result)
1
+
1
15. • There are three ways in which signed binary numbers
may be expressed:
– Signed magnitude,
– One’s complement and
– Two’s complement.
• In an 8-bit word, signed magnitude representation places
the absolute value of the number in the 7 bits to the
right of the sign bit.
• For example, in 8-bit signed magnitude, positive 3 is:
00000011
• Negative 3 is: 10000011
Signed Integer Representation
16. One's Complement
• The one's complement of an integer is obtained by
complementing each bit; that is, replace each 0 by a 1 and
each 1 by a O. In the following , we assume numbers are 16
bits.
• Example : Find the one's complement of 5 =
0000000000000101.
Solution: 5= OOOOOOOOOO0OO I 0 I
One's complement of 5 = 1111111111111010
Note that if we add 5 and its one's complement, we get
1111111111111111.
17. Two's Complement
Representation
• Start at the least significant digit, leaving all the
0s unchanged, look for the first occurrence of a
non-zero digit.
Example: Find the two's complement of the 5.
Solution:
5=00000000000000101
Ones complement of 5 =1111111111111010
+1
two's complement of 5 = 1111111111111011
18. Here is my basic idea of how the program should
be structured in number system:
• org 100h
• mov al, 00000101b ; (hex: 5h)
mov bl, 0ah
• mov cl, 10o
• Add al, bl ; 5 + 10 = 15 (0fh) ; 15 - 8 = 7
• sub al, cl
• mov bl, al ; print result in binary:
• mov cx, 8
• print:
• mov ah, 2 ; print function.
• mov dl, '0'
• test bl, 10000000b ; test first bit.
• jz zero
• mov dl, '1'
• zero:
• int 21h
• shl bl, 1
• loop print
• mov dl, 'b'
• int 21h
• mov ah, 0
• int 16h
• ret