Вы находитесь на странице: 1из 105

ASCII CODE

ASCII CODE
 ASCII : American Standard Code for Information
Interchange
 Use bit patterns of length seven to represent
 Letters of English Alphabet : a – z and A – Z
 Digits : 0 – 9
 Punctuation Symbols : (, ), [, ], {, }, ’, ”, !, /, \
 Arithmetic Operation symbols: +, -, *, <, >, =
 Special symbols: (space), %, $, #, &, @, ^
 27 = 128 characters can be represented by ASCII
CHARACTER REPRESENTATION: ASCII TABLE
 The BINARY string 0110101 can have two meanings!
What are those?
1. The CHARACTER “5” in ASCII
2. The DECIMAL NUMBER 53 in BINARY Notation
UNICODE
 Why UNICODE?
 EBCDIC and ASCII are built around the Latin alphabet
 Are restricted in their ability for representing non-Latin alphabet
 Countries developed their own codes for native languages

 UNICODE:
 16-bit system that can encode the characters of most languages
 16 bits = 216 = 65,636 characters
 The Java programming language and some operating
systems now use Unicode as their default character
code
 Downward compatible with ASCII and Latin-1 character
sets
BINARY
ARITHMETIC
BINARY ADDITION
 0+0=0
 0+1=1
 1+0=1
 1 + 1 = 10 (carry: 1)
BINARY ADDITION

Carry

0 1 1 0 1

1 0 1 1 1
BINARY ADDITION

Carry

0 1 1 0 1

1 0 1 1 1

0
BINARY ADDITION

1 Carry

0 1 1 0 1

1 0 1 1 1

0
BINARY ADDITION

1 Carry

0 1 1 0 1

1 0 1 1 1

0 0
BINARY ADDITION

1 1 Carry

0 1 1 0 1

1 0 1 1 1

0 0
BINARY ADDITION

1 1 Carry

0 1 1 0 1

1 0 1 1 1

1 0 0
BINARY ADDITION

1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

1 0 0
BINARY ADDITION

1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

0 1 0 0
BINARY ADDITION

1 1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

0 1 0 0
BINARY ADDITION

1 1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

0 0 1 0 0
BINARY ADDITION

1 1 1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

0 0 1 0 0
BINARY ADDITION

1 1 1 1 1 Carry

0 1 1 0 1

1 0 1 1 1

1 0 0 1 0 0
BINARY SUBTRACTION
 0-0=0
 0 - 1 = 1 (with borrow)
 1-0=1
 1-1=0
BINARY SUBTRACTION

(borrow)

0 1 1 0 1
1
- 0 1 0 1 1 1
BINARY SUBTRACTION

(borrow)

0 1 1 0 1
1
- 0 1 0 1 1 1

0
BINARY SUBTRACTION

(borrow)
*
0 1 1 0 1
1
- 0 1 0 1 1 1

1 0
BINARY SUBTRACTION

(borrow)
* *
0 1 1 0 1
1
- 0 1 0 1 1 1

1 1 0
BINARY SUBTRACTION

(borrow)
* *
0 1 1 0 1
1
- 0 1 0 1 1 1

0 1 1 0
BINARY SUBTRACTION

(borrow)
* * *
0 1 1 0 1
1
- 0 1 0 1 1 1

1 0 1 1 0
BINARY SUBTRACTION

(borrow)
* * *
0 1 1 0 1
1
- 0 1 0 1 1 1

0 1 0 1 1 0
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0

0 0 0 0
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0

0 0 0 0

1 0 1 1
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0

0 0 0 0

1 0 1 1

0 0 0 0
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0

0 0 0 0

1 0 1 1

0 0 0 0

1 0 1 1
BINARY MULTIPLICATION
1 0 1 1

1 0 1 0

0 0 0 0

1 0 1 1

0 0 0 0

1 0 1 1

1 1 0 1 1 1 0
BINARY DIVISION

1 0 1 1 1 0 1 1
BINARY DIVISION
1
1 0 1 1 1 0 1 1
BINARY DIVISION
1
1 0 1 1 1 0 1 1
1 0 1
BINARY DIVISION
1
1 0 1 1 1 0 1 1
1 0 1
0 0 1
BINARY DIVISION
1
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
BINARY DIVISION
1 0
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
BINARY DIVISION
1 0
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
BINARY DIVISION
1 0
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
1 1
BINARY DIVISION
1 0
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
1 1 1
BINARY DIVISION
1 0 1
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
1 1 1
BINARY DIVISION
1 0 1
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
1 1 1
1 0 1
BINARY DIVISION
1 0 1
1 0 1 1 1 0 1 1
1 0 1
0 0 1 1
0 0 0
1 1 1
1 0 1
1 0
EXERCISE – BINARY ARITHMETIC
1 1 0 1 1 0 1 0
+ 1 1 1 - 1 1 1

1 0 1 1
X 1 0 101 1 0 1 1
ANSWER – BINARY ARITHMETIC
1 1 0 1 1 0 1 0
+ 1 1 1 - 1 1 1
1 0 1 0 0 0 0 1 1

1 0 1 1 1 0
X 1 0 101 1 0 1 1
0 0 0 0 1 0 1
1 0 1 1 0 1
1 0 1 1 0
PRESENTING
NUMBER
NUMBER REPRESENTATION
 Different ways to represent numbers
 Unsigned representation : non-negative integers
 Signed representation : integers
 Floating-point representation: fractions
UNSIGNED BINARY NUMBERS
 Have 0 and 1 to represent numbers
 Only positive numbers stored in binary

 Smallest number : 0 0 0 0 0 0 0 0 which equals to 0


 Largest number : 1 1 1 1 1 1 1 1 which equals 255

 Range : 0 – 255 (256 numbers)


UNSIGNED BINARY NUMBERS
 Represent decimal number 178 in unsigned binary
representation
SIGNED BINARY NUMBERS

 Have 0 and 1 to represent numbers


 Stores both positive and negative numbers
 Sign bit : Leftmost bit
 0 for positive
 1 for negative

Sign
bit
SINGED BINARY NUMBERS
 Smallest positive number 0 0 0 0 0 0 0 0 which
equals to 0
 Largest positive number 0 1 1 1 1 1 1 1 which equals
to 127

 Range of positive number : 0 – 127 (128 numbers)


SIGNED BINARY NUMBERS
 Write singed representation
 17
 -17
NEGATIVE NUMBERS IN BINARY
 Two’s complement
 Start from singed binary representation of its positive value
 Complement the remaining bits : all the 1’s with 0’s and all the 0’s
with 1’s
 Add 1 to the lease significant bit
TWO’S COMPLEMENT REPRESENTATION

Represent -15 in 2’s complement.

+15 = 0 0 0 0 1 1 1 1

-15 = 1 1 1 1 0 0 0 0

1 1 1 1 0 0 0 1
What is the SMALLEST and LARGEST
signed binary numbers that can be
stored in 1 BYTE
0 1 1 1 1 1 1 1 +127
. . . . . . . .
0 0 0 0 0 0 1 1 +3
0 0 0 0 0 0 1 0 +2
0 0 0 0 0 0 0 1 +1
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 -1
1 1 1 1 1 1 1 0 -2
1 1 1 1 1 1 0 1 -3
. . . . . . . .
1 0 0 0 0 0 0 1 -127

1 0 0 0 0 0 0 0 -128
TWO’S COMPLIMENT BENEFITS
 One representation of zero
 Arithmetic works easily
 Negating is fairly easy
TWO’S COMPLEMENT REPRESENTATION
 Write down two’s complement representation for the
decimal numbers 39 and -39.
RANGES OF INTEGER REPRESENTATION
 8-bit unsigned binary representation
 Largest number: 1 1 1 1 1 1 1 12 = 25510
 Smallest number: 0 0 0 0 0 0 0 02 = 010

 8-bit two’s complement representation


 Largest number: 0 1 1 1 1 1 1 12 = 12710
 Smallest number: 1 0 0 0 0 0 0 02 = -12810
INTEGER DATA TYPES

Size in
Type Range
Bits

Unsigned int 16 0 – 65,535

Int 16 -32,768 – 32,767

Unsigned long 32 0 to 4,294,967,295


int
Long int 32 -2,147,483,648 to
2,147,483,647
FRACTIONS IN DECIMAL
 10.0112 in Decimal equals to ……………
 10.011 = 1x21 + 0 x 20 + 0 x 2-1 + 1 x 2-2 + 1 x 2-3
= 2 + 0 + 0 + 1/ 4 + 1/ 8
= 2 3/8 10
FRACTIONS IN DECIMAL
 Convert decimal number 19.825 to binary

19 ÷ 2 = 9  Remainder 1
9÷2=4  Remainder 1
4÷2=2  Remainder 0
2÷2=1  Remainder 0
1÷2=0  Remainder 1
1910 = 100112
FRACTIONS IN DECIMAL
0.825 X 2 = 1.650 1
0.650 X 2 = 1.300 1
0.300 X 2 = 0.600 0
0.600 X 2 = 1.200 1

0.82510 = 0.11012

19.82510 = 10011.11012
FLOATING POINT REPRESENTATION OF
FRACTIONS

Scientific notation for binary

Mantissa Exponent

11011.101 = 1.1011101 x 24

Base
FLOATING POINT FORMAT IN 1 BYTE
Radix Point
.

Sign Exponent Mantissa


In Excess Four Notation
0 (+ve)

1 (-ve)
Store 21/8 in floating point notation
21/8 10 = 10.001 = 1.0001 x 21

0 0 0 0 1

Exponent  Excess K notation


EXCESS K REPRESENTATION

Bit Valu  N : bits allocated for exponent = 3


Patter e  K = 2N-1 – 1 = 23-1 – 1 =3
n
111 4 Value of each bit string = unsigned value – K
110 3
101 2 To represent a number in excess-K, add K
100 1
011 0
010 -1
001 -2
000 -3
21/8 10 = 10.001 = 1.0001 x 21

0 1 0 0 0 0 0 1

Exponent  Excess K notation


EXERCISE
 Represent -31/4 in floating point notation
CONVERT FP BINARY TO DECIMAL

 Convert 10111010 to decimal

1 0 1 1 1 0 1 0
CONVERT FP BINARY TO DECIMAL

 Convert Exponent

1 0 1 1 1 0 1 0

 Exponent = 011
=3–3=0
CONVERT FP BINARY TO DECIMAL

 Apply Exponent to Mantissa


.
1 1 0 1 0
CONVERT FP BINARY TO DECIMAL

 Convert Binary fraction


.
1 1 0 1 0

 1.10102 = 1 + ½ + 1/8 = 15/8


CONVERT FP BINARY TO DECIMAL

 Apply Sign

1 0 1 1 1 0 1 0

Answer : -15/8
ROUND-OFF ERRORS

 Calculate Round-off errors for 35/16

 3.3125 = 11.0101
= 1.10101 x 21

0 1 0 0 1 0 1 0 1
ROUND-OFF ERRORS

0 1 0 0 1 0 1 0 1

1.1010 x 21 = 11.0102
11.010 = 3 + 1/4 = 31/4

Round off error = 1/16


RANGE OF FP REPRESENTATION

 What is the biggest positive number can be


represented by one-bye floating point
notation ?

0 1 1 1 1 1 1 1

+1.1111 x 24 = 11111 = 3110


RANGE OF FP REPRESENTATION

 What is the smallest positive number can


be represented by one-bye floating point
notation ?

0 0 0 0 0 0 0 0

+1.0000 x 2-3 = +0.001 = 1/8


RANGE OF FP REPRESENTATION

 What is the largest negative number can be


represented by one-bye floating point
notation ?

1 0 0 0 0 0 0 0

-1.0000 x 2-3 = -0.001 = -1/8


RANGE OF FP REPRESENTATION

 What is the smallest negative number can


be represented by one-bye floating point
notation ?

1 1 1 1 1 1 1 1

-1.1111 x 24 = -11111 = -3110


FLOATING POINT DATA TYPES

Size in
Type Range
Bits
3.4E-38 to 3.4E+38
Float 32
Six digits of precision
1.7E-308 to 1.7E+308
Double 64
Ten digits of precision
3.4E-4932 to
Long
80 3.4E+4932
double
Ten digits of precision
IEEE FLOATING POINT FORMAT

Sign Biased Significant or


Bit Exponent Mantissa

Field width Single Double Quad


in bits Precision Precision Precision
S = sign 1 1 1
E = Exponent 8 11 15
L = Leading 1 1 1
bit
F = Fraction 23 52 111
Total width 32 64 128
IEEE FLOATING POINT FORMAT

Exponent Single Double Quad


Precision Precision Precision
Maximum E 255 2047 32767
Minimum E 0 0 0
Bias 127 1023 16383

 Note
 S – sign bit (1 for negative number and 0 for positive
number)
 L – leading bit (always 1 in a normalized, non-zero
mantissa)
EXAMPLE : IEEE FP REPRESENTATION
 Represent -100100101001.0012
-100100101001.0012 = 1.00100101001001 x 211
Sign : 1
Biased exponent : 11 + 127 = 138 = 100010102
Fractional part of mantissa :0.00100101001001000000000

1 10001010 00100101001001000000000
IEEE FP REPRESENTATION
 Represent following numbers using IEEE
Floating point representation.
32.562510
-1 0 1 0 1 1 1 0 1 1 0 . 1 0 1 0 1 0 2
1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 1 . 1 1 1 0 0 0 12
QUESTIONS
1 Which of the following is the range of integers which
can be represented using two’s complement notation
on a 16-bit register?

 -32768 to +32768
 -65536 to +65536
 -65536 to +65536
 -32767 to +32767
 -32768 to +32767
2 What is the binary equivalent of the hexadecimal
number ABCD?

 1010 1011 0101 0101


 1010 1011 1100 1101
 0011 1011 0101 1111
 1011 1011 0101 0101
 1011 1011 1100 0101
3 The number 0111111111111111 in the form of
Two’s Complement is be equivalent to decimal
number

 -65535
 +32768
 +65535
 +32767
 -65536
4 The equivalent in hexadecimal to the decimal
number 973 is

 4BC
 CB4
 6D
 6CD
 3CD
5 The equivalent in binary to the hexadecimal
number A7FE is

 101101111111110
 1010011111111110
 1010100101111110
 101101111111111
 1011011111101110
6 The equivalent in binary to the decimal number
4.625 is

 100.001
 100.110
 100.111
 100.101
 100.1001
7 Which unsigned binary number in the result of the
subtraction of unsigned binary number 00101101
from the unsigned binary number 10111001?

 01110011
 10001100
 00001100
 01110100
 10001101
8 The result of the addition of the unsigned binary
number 101.101 by the unsigned binary number
1011.110 is

 11110.111
 10001.011
 10000.111
 10001.111
 10000.011
9 The result of the subtraction of binary number
11101.110 from the binary number 101101.101 is

 111.001
 1111.001
 1111.111
 111.111
 111.101
10 The binary number 1011011011101 is equivalent
to (consider the decimal, octal and hexadecimal
number systems)

 16DD
 13335
 16CC
 5855
 5851
11 The decimal number 6949 is equivalent to
(consider the binary, octal and hexadecimal
number system)

 1010010011011
 17449
 1F23
 1101100100101
 17445
12 Which binary number in the form of two’s
complement is the result of the subtraction of
binary number 100011 from the binary number
1110101?

 1001101
 1001110
 1001101
 1010010
 01110101
Consider the following binary patterns
13
A : 01010100
B : 00110111

Which of the following is / are true?


 Decimal equivalent of A is 84 and that of B is 55
 Decimal equivalent of A is 83 and that of B is 54
 Sum of A and B is given by the primary pattern
10001011
 Sum of A and B is given by the binary pattern
01100011
 Sum of A and B is given by the binary pattern
00011101
14 The IEEE short floating point representation of
the binary number -1001.1011 is
 0 00000011 00110110000000000000000
 1 00000011 00000000000000000011011
 1 10000010 00110110000000000000000
 1 00011011 00000000000000000000011
 1 00011011 11000000000000000000000

Вам также может понравиться