1 of 31

Chapter 2

Signed and Unsigned Numbers

Representation of integers base 2, 10, and 16, conversion between bases. Binary addition and subtraction

2 of 31

 �Signed and unsigned numbers

  • Humans think in base 10, but numbers may be represented in any base. For example, 12310 = 11110112.
  • Numbers are kept in computer hardware as a series of high and low electronic signals, and so they are considered base 2 numbers.
  • A single digit of a binary number is thus the "atom" of computing, since all information is composed of binary digits or bits.
  • Binary digit: Also called a bit. One of the two numbers in base 2 (0 or 1) that are the components of information.
  • Just as base 10 numbers are called decimal numbers, base 2 numbers are called binary numbers.

3 of 31

Binary Numbers(Review)

  • In assembly language it is important to remember that the actual hardware to be used only understands binary values 0 and 1.
  • Binary values 0 and 1 are called binary numbers
  • The numbering system that everyone learns in school is called decimal or base 10.
  • The numbering system is called decimal because it has 10 digits, [0..9].
  • Binary Numbers uses base 2 numbering system
  • In binary, there are only two digits, 0 and 1.

4 of 31

How does a computer represent numbers? (Review)

  • Numbers are kept in computer hardware as a series of high and low electronic signals, and so they are considered base 2 numbers
  • Computers use switches that can be either on (1) or off(0), and so computers use the binary numbering system (base 2 numbering system)
  • A single digit of a binary number is thus the "atom" of computing, since all information is composed of binary digits or bits. 
  • Binary digit: Also called a bit. One of the two numbers in base 2 (0 or 1) that are the components of information.

5 of 31

�How to convert binary to decimal?

  • decimal = d0×20 + d1×21 + d2×22 + ...
  • Generalizing the point, in any number base, the value of i th digit d is

d×Basei

Example:

6 of 31

Example 1:

  • What is 1110two in base ten?
  • Solution:

(1 * 23) + (1 * 22) + (1 * 21) + (0 * 20)

(1 * 8) + (1 * 4) + (1 * 2) + (0 * 1)

8 + 4 * 2 + 0

14

7 of 31

Example 2:

  • What is 1011two in base ten?
  • Solution:

(1 * 23) + (0 * 22) + (1 * 21) + (1 * 20)

(1 * 8) + (0 * 4) + (1 * 2) + (1 * 1)

8 + 0 * 2 + 1

11

  • What is 111001two in base ten?
  • What is 100011two in base ten?

8 of 31

Example 3:

  • What is 111001two in base ten?
  • Solution:

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

(1 * 32) + (1 * 16) + (1 * 8) + (0 * 4) + (0 * 2) + (1 * 1)

32 + 16 * 8 + 0 + 0 + 1

57

  • What is 100011two in base ten?

9 of 31

Example 4:

  • What is 100011two in base ten?
  • Solution:

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

(1 * 32) + (0 * 16) + (0 * 8) + (0 * 4) + (0 * 2) + (1 * 1)

32 + 0 * 0 + 0 + 2 + 1

25

10 of 31

�Decimal to Binary Conversions

  • Conversion steps:
    • Divide the number by 2.
    • Get the integer quotient for the next iteration.
    • Get the remainder for the binary digit.
    • Repeat the steps until the quotient is equal to 0.

11 of 31

Example 1

  • Convert 1310 to binary:

Division by 2

Quotient

Remainders

Bit #

13/2

6

1

0

6/2

3

0

1

3/2

1

1

2

1/2

0

1

3

Writing the remainders from bottom to top, we have: 1310 = 11012

12 of 31

Example 2

  • Convert 14710 to binary:

Division by 2

Quotient

Remainders

Bit #

147/2

73

1

0

73/2

36

1

1

36/2

18

0

2

18/2

9

0

3

9/2

4

1

4

4/2

2

0

5

2/2

1

0

8

1/2

0

1

7

Writing and reading the remainders from bottom to top, we have: 14710 = 100100112

13 of 31

Converting Fractions

  • Fractions in any base system can be approximated in any other base system using negative powers of a radix.
  • Radix points separate the integer part of a number from its fractional part.
  • In the decimal system, the radix point is called a decimal point. Binary fractions have a binary point

14 of 31

Conversion steps for fractions:

  • Multiply the fractional decimal number by 2.
  • Integral part of resultant decimal number will be first digit of fraction binary number.
  • Repeat step 1 using only fractional part of decimal number and then step 2.

15 of 31

Example 1

  • Convert 0.3437510 to binary with 4 bits to the right of the binary point.

Reading from top to bottom, 0.3437510 = 0.01012 to four binary places.

16 of 31

Hexadecimals

  • A Hexadecimal Number is based on the number 16
  • There are 16 Hexadecimal digits. They are the same as the decimal digits up to 9, but then there are the letters A, B, C, D, E and F in place of the decimal numbers 10 to 15:

Hexadecimal:

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Decimal:

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

17 of 31

Some Numbers to remember

18 of 31

Convert Binary to Hexadecimal

  • Binary numbers are often expressed in hexadecimal to improve their readability.
  • Example: Convert 1100100111012 to hexadecimal.
  • Solutions:

  • If there are too few bits, leading zeros can be added.

19 of 31

Signed and Unsigned Numbers

  • Computer programs calculate both positive and negative numbers, so we need a representation that distinguishes the positive from the negative
  • Unsigned numbers stored only positive numbers but do not store negative numbers.
  • Signed numbers use sign flag or can be distinguish between negative values and positive values.
  • Number representation techniques like: Binary, Decimal and Hexadecimal number representation techniques that we have discussed above can represent numbers in both signed and unsigned ways

20 of 31

signed binary and Unsigned binary

  • Unsigned binary numbers do not have sign bit
  • Signed binary numbers uses signed bit and magnitude
    • The most obvious solution is to add a separate sign, which conveniently can be represented in a single bit; the name for this representation is sign and magnitude
    • Two’s complement representation: leading 0s mean positive, and leading 1s mean negative.
  • Signed integers is the set of positive and negative integers

21 of 31

Unsigned Numbers:

  • Unsigned numbers do not have any sign as they only represent positive numbers
  •  Represent decimal number 9210 in unsigned binary number.

= (1x26+0x25+1x24+1x23+1x22+0x21+0x20)10

= (1011100)2 a 7-bit binary magnitude of the decimal number 9210.

  • You can also used division to get to the above above answer

22 of 31

Signed Numbers:

  • Signed numbers contain sign flag ro distinguish positive and negative numbers.
  • This technique contains both sign bit and magnitude of a number.
  • Three types of representations for signed binary numbers
    • Sign-Magnitude form
    • 1’s complement form
    • 2’s complement form

23 of 31

Sign-Magnitude form

  • For n bit binary number, 1 bit is reserved for sign symbol.
  • If the value of sign bit is 0, the given number is positive, else if the value of sign bit is 1, the given number is negative.
  • Remaining (n-1) bits represent magnitude of the number

24 of 31

Sign-Magnitude form Conversions Example

  • What are the decimal values of the following 8-bit sign-magnitude numbers?
    • 10000011 = -3
    • 00000101 = +5
    • 11111111 = -127
    • 01111111 = 127

25 of 31

Sign-Magnitude form Conversions Example

  • Represent the following in 8-bit sign-magnitude
    • -15 = 10001111
    • +7 = 00000111
    • -1 = 1001

26 of 31

1’s complement form

  • Positive values in one's complement are the same as unsigned binary or sign-magnitude.
  • To negate a one's complement value, we invert all bits. Like sign-magnitude, one's complement has two representations for zero (all zeros or all ones).

27 of 31

Conversions Example

  • What are the decimal values of the following 8-bit one's complement numbers?
    • 00001010 = +10
    • 10001010 = -(01110101) = -(1+4+16+32+64) = -117
    • 11111111 = ?

28 of 31

�2's Complement Form�

  • Commonly used
  • A positive integer in two's complement always has a 0 in the leftmost bit (sign bit) and is represented the same way as an unsigned binary integer.
  • To negate a number, a process sometimes called “taking the two's complement”, we invert all the bits and add one.

29 of 31

Conversion Example

  • Example 1
    • +1410 = 01110two's comp

  • Example 2:
    • -1410 = 10001 + 1
    • = 10010two's comp

30 of 31

  • Convert the following 4-bit 2's comp values to decimal:
    • 0111 = +(1 + 2 + 4) = +7
    • 1000 = -(0111 + 1) = -(1000) = -8
    • 0110 = +(2 + 4) = +6
    • 1001 = -(0110 + 1) = -0111 = -(1 + 2 + 4) = -7
    • 1110 = -(0001 + 1) = -0010 = -2

31 of 31

Readings

  • Chapter 2.5 to 2.7