1 / 34

# Numbers Systems and Codes - PowerPoint PPT Presentation

Week 2: Number Systems and Codes A. Berrached 1 Numbers Systems and Codes How is information represented at the gate-level? Only two symbols: 0 and 1 Information is coded using string combinations of 0s and 1s. A code is a standard set of rules for representing and interpreting information

Related searches for Numbers Systems and Codes

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Numbers Systems and Codes' - salena

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Week 2:Number Systems and Codes

A. Berrached

1

How is information represented at the gate-level?

• Only two symbols: 0 and 1

• Information is coded using string combinations of 0s and 1s.

• A code is a standard set of rules for representing and interpreting information

• Information:

• Numerical: unsigned and signed numbers

• Binary Coded Decimal codes

• Characters (textual information)

Positional Notation (polynomial notation)

• a number is represented with a string (sequence) of digits

• the position of each digit in the sequence carries a weight

Example: decimal system

• base 10 => 10 digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

• 4175.86 =

5*100 + 7* 101 + 1* 102 +4* 103 + 8* 10-1 +6* 10-2

• In base 10:

If a number N =dn-1dn-2 ….d1d0 .d-1… d-m

then

N = dn-1*10n-1 + dn-2*10n-2 +….+ d1*101 + d0*100

+ d-1*10-1 + ... + d-m*10-m

• In any base r:

If a number (N)r = dn-1dn-2 ….d1d0 .d-1… d-m

then

(N)r = dn-1*rn-1 + dn-2*rn-2 +….+ d1*r1 + d0*r0

+ d-1*r-1 + ...+ d-m*r-m

N = 1101101.1012

N = (1*26) + (1*25) + (0*24) + (1*23) + (1*22) + (0*21) + (1*20) +

(0*2-1) + (1*2-2) + (1*2-3)

N = 64 + 32 + 0 + 8 + 4 + 0 + 1 + 1/2 + 0/4 + 1/8 in base 10

N = 109.625 in base 10

=> N = (109.625)10

To convert a number N from base b to base 10use method as shown above (series substitution method)

• From base b to base 10

• use series substitution method

• do arithmetic in base 10.

• From base 10 to base b

• Integer part

• use successive divisions by b, until quotient is 0

• collect remainders: first remainder is the least significant digit

• fraction part

• use successive multiplication by b

• collect integer part of each product

• Conversion from base A to base B

• convert number from base A to base 10

• covert resulting number from base 10 to base B.

• Special cases

• Conversion frombinary to octal

• Conversion from octal to binary

• Conversion from hexadecimal to binary

• Unsigned Binary Code

• Signed Binary Codes

• 2’s Complement System

• BCD Code

• Excess Codes

• Floating-Point System

• Given a number N in Unsigned Binary code, find the value of N in the decimal system

• Use series substitution method

• Given a number N in the decimal system, find the value of N in the Unsigned Binary Code.

• Use successive division method (for integer part)

• Use successive multiplication method (for fraction part)

• Example 1: Represent (26)10 in Unsigned Binary Code

2610 = 11010

• Example 2: Represent (26)10 in Unsigned Binary Code using 8 bits.

2610 = 00011010

• Example 3:Represent (26)10 in Unsigned Binary Code using 4 bits.

Can’t do. Not enough bits.

• The Unsigned Binary Code is used to represent positive integer numbers.

• What is the range of values that can be represented with n bits in the Unsigned Binary Code?

[0, 2n-1]

• How many bits are required to represent a given number N?

number of bits = smallest integer greater than or equal to log(N)

• Arithmetic Operations:

• Subtraction

• Multiplication

• Division

• Logic Operations

• AND CONJUNCTION

• OR DISJUNCTION

• NOT NEGATION

• XOR EXCLUSIVE OR

These are codes used to represent positive and negative numbers.

• Sign and Magnitude Code

• 1’s Complement Code

• 2’s Complement Code

• The leftmost bit is the sign bit

• 0 for positive numbers

• 1 for negative numbers

• The remaining bits represent the magnitude of the number

Example:

Sign & Mag. CodeDecimal

01101 +13

11101 -13

00101 +5

10101 -5

What is the range of values that can be represented in S&M code with n bits?

• Example 1: Represent (26)10 in Sign & Magnitude Code.

2610 = 011010

• Example 2: Represent (26)10 in Sign & Magnitude Code using 8 bits

2610 = 0001 1010

• Example 3: Represent (26)10 in Sign & Magnitude Code using 5 bits.

• Need at least 6 bits.

• Example 1: Represent (-26)10 in Sign & Magnitude Code.

• 26 = 11010

• -2610 = 111010

• Example 2: Represent (-26)10 in Sign & Magnitude Code using 8 bits

• 26 = 00011010

• - 2610 = 10011010

• Example 3: Represent (-26)10 in Sign & Magnitude Code using 5 bits.

• Need at least 6 bits.

• Positive numbers:

• same as in unsigned binary code

• pad a 0 at the leftmost bit position

• Negative numbers:

1. Represent the magnitude of the number in unsigned binary system

2. pad a 0 at the leftmost bit position

3. complement every bit

• Example: represent 2610 in 1’s complement code

• 2610 = 11010

• Pad a 0: = 011010

• Example: Represent (-26)10 in 1’s complement code.

1. 26= 11010

3. Complement: 100101(-26)10 = (100101)1’s comp

• Example: Represent (-26)10 in 1’s comp. code using 8 bits

1. Represent magnitude in unsigned binary using 8 bits

26 = 0001 1010

2. Complement every bit

11100101

-2610 = (1110 0101) 1’s comp

What is the range of values that can be represented in S&M code with n bits?

[ -(2 (n-1) -1) , 2(n-1) -1]

• This is the code commonly used to represent integer numbers.

• Positive Numbers:

• same as in unsigned binary code

• pad with a 0 leftmost bit position

• Negative Numbers

1. represent magnitude in unsigned binary code

2. pad leftmost positions with 0s

3. complement every bit

• Example 1: Represent 26 in 2’s complement code.

26 = 011010

• Example 2: Represent 26 in 2’s complement code using 8 bits

26 = 00011010

• Example 3: Represent 26 in 2’s complement code using 5 bits

• Need at least 6 bits.

• Example 3: Represent - 26 in 2’s comp. Code

1. +26 = 11010

2. Pad with a 0: 011010

3. Complement: 100101

---------------

100110

• Example 4: Represent - 26 in 2’s comp. Code using 8 bits

1. +26 = 11010

3. Complement: 11100101

---------------

11100110

• More example: represent 65 in 2’s comp. Code.

• 65 = (0100 0001)2’s comp

• Represent - 65 in 2’s comp

• 65 = 0100 0001

• -65 = 1011 1111

• How to convert a number in 2’s Comp. Code into the decimal code.

There 2 cases:

Case 1: If leftmost bit of the number is 0

=> number is positive

=> conversion is the same as in unsigned binary code

Case 2: If leftmost bit is 1

=> the number is negative

step1: complement every bit

step3: convert result to decimal code using same method as in unsigned binary code.

Answer = the negative of the result of step 3.

Range of values with n bits:

[ -2 (n-1), 2(n-1) -1]

• Subtraction

• Overflow

• There are 16 digits:

• 0 1 2 3 4 5 6 7 8 9 A B C D E F

• Each Hex digit represents a group of 4 bits (i.e. half of a byte) 0000 thru 1111

• Generally used as shorthand notation for binary numbers => easier to read

• Binary: 0101 1010 1001 1110

• Decimal: 5 10 9 14

• Hex: 5 A 9 E

• Examples:

• Binary: 1111 0110

• Hex: F6

• Binary: 1001 1101 0000 1010

• Hex: 9D0A

• Hex: F6E7

• Binary 1111 0110 1110 0111

• A number is a sequence of decimal digits

• Each digit is represented with a 4-bit number.

• BCD codes allow easy conversion to/from decimal system

Natural Binary Coded Decimal Code (the BCD code)

• each decimal digit is represented with 4 bits in base 2

e.g. 0 = 0000 3 = 0011 5= 0101 9 = 1001

• N = 856.3710

• N = 1000 0101 0110 . 0011 0111BCD