19
Representation Of Numbers and Characters Our Presentation Topic is

Representation Of Numbers and Characters

Embed Size (px)

Citation preview

Page 1: Representation Of Numbers and Characters

Representation Of Numbers andCharacters

Our Presentation Topic is

Page 2: Representation Of Numbers and Characters

Our Group Members are:Name Id

Mohammad Obaedul Islam

4080

Shaikh Kamrul Islam 3814

Debashish Mondal 3709

Ashraful Alam Sabbir 4086

Page 3: Representation Of Numbers and Characters

Outline• Introduction• Numbering Systems• Binary & Hexadecimal Numbers• Binary and Hexadecimal Addition• Binary and Hexadecimal subtraction• Base Conversions

Page 4: Representation Of Numbers and Characters

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

Page 5: Representation Of Numbers and Characters

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:

Page 6: Representation Of Numbers and Characters

Conversion of Number System:

Page 7: Representation Of Numbers and Characters

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 169Conversion :(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

Page 8: Representation Of Numbers and Characters

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.

Page 9: Representation Of Numbers and Characters

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

Page 10: Representation Of Numbers and Characters

• 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.

Page 11: Representation Of Numbers and Characters

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

Page 12: Representation Of Numbers and Characters

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 6A42 45 58 4B78 6D 80 B5

11

21 / 16 = 1, remainder 5

Important skill: Programmers frequently add and subtract the addresses of variables and instructions.

Page 13: Representation Of Numbers and Characters

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)

Page 14: Representation Of Numbers and Characters

When a borrow is required from the digit to the left, add 16 (decimal) to the current digit's value

Hexadecimal Subtraction

C675A247242E

-1

-

16 + 5 = 21

C6755DB9 (2's complement)

242E (same result)

1

+1

Page 15: Representation Of Numbers and Characters

• 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

Page 16: Representation Of Numbers and Characters

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 IOne's complement of 5 = 1111111111111010Note that if we add 5 and its one's complement, we get1111111111111111.

Page 17: Representation Of Numbers and Characters

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=00000000000000101Ones complement of 5 =1111111111111010 +1two's complement of 5 = 1111111111111011

Page 18: Representation Of Numbers and Characters

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

Page 19: Representation Of Numbers and Characters

THANK YOU ALL