Docsity

Binary Numbering System, Signed and Unsigned Numbers | CS 35101, Study notes of Computer Architecture and Organization

Partial preview of the text

Download Binary Numbering System, Signed and Unsigned Numbers | CS 35101 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Computer Architecture

Chapter 3

Fall 2005 Department of Computer Science Kent State University

Objectives

  • Signed and Unsigned Numbers
  • Addition and Subtraction
  • Multiplication and Division
  • (^) Floating Point
  • Information inside a digital computer is stored as

a collection of “binary data”

  • Binary numbering system
    • (^) Base-
    • Built from ones and zeros
    • Each position is a power of 2 1101 = 1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0
    • Digits 0,1 are called bits (binary digits) Binary Representation of Numbers

Binary Representation of Numbers

  • 6-Digit Binary Number (111001)
    • 111001 = 1 x 2 5 + 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 0 x 2 1 + 1 x 2 0 = 32 + 16 + 8 + 0 + 0 + 1 = 57
  • 5-Digit Binary Number (10111)
    • 10111 = 1 x 2 4 + 0 x 2 3 + 1 x 2 2 + 1 x 2 1 + 1 x 2 0 = 16 + 0 + 4 + 2 + = 23

31 30 29 28 .... .... .... .... .... 7654 3210 0 0 0 0 0000 0000 0000 0000 0000 0000 1011 Number Representation MIPS word Example: how to translate (^11) ten into binary? (^11) ten = 1 x 2 3

  • 0 x 2 2
  • 1 x 2 1
  • 1 x 2 0 = (^1011) two Most-significant bit Least-significant bit How many (unsigned) binary numbers can 32 bits represent?

How to represent negative numbers?

  • You have a budget of 32 bits to represent positive numbers and negative numbers. In other words, you need to map any 32-bit code to a (binary) number
  • You need to make some (simple) rules so that in your system, you will be able to recognize/separate positive numbers and negative numbers very easily
  • Questions
    • In your system, how many positive number and negative number you can express?
    • In your system, how to perform add and sub operation?

Signed-Magnitude

  • (^) Explicit sign bit
  • Remaining bits encode unsigned magnitude
  • Two representations for zero (+0 and -0)
  • Addition and subtraction are more complicated 111 - 110 - 101 - 100 - 011 + 010 + 001 + 000 + Representation Value

Biased

  • (^) Add a bias to the signed number in order to make it unsigned
  • Subtract the bias to return the original value
  • Typically the bias is 2 k - for a k -bit representation 111 3 110 2 101 1 100 0 011 - 010 - 001 - 000 - Representation Value

Signed Number Representation

Two’s Complement Notation  (^) Leading 0s mean +ve  (^) Leading 1s mean -ve 1 0 0 0 0000 0000 0000 0000 0000 0111 0001 1 x –2^31 + 0 X2^30 + …1x2^6 + 1x2^5 + 1x2^4 + 0x2^3 + 0x2^2 +0x2^1 +1x2^0 = -2,147,483,648 + 64 + 32 + 16 + = -2,147,483, Compare with sign/magnitude representation for -

cf: Sign Magnitude/ Two’s Complement Notations Up Close Sign Magnitude Two's Complement

Some basic questions

  • Consider you have a number (52, -52) in

decimal, how do transform it into the Two’s

complement binary representation?

  • How to perform add or sub operation in

such a system?

Review

  • What’s is two’s complement notation?

Sign/magnitude?

  • 1011, 0011^ ^ decimal (assume we only

have 4 bits)

  • Express -3 and 3 in two’s complement

notation (8 bits)

  • Addition (carries 1s) 0000 0000 0000 0000 0000 0000 0000 0011 = + 3 0000 0000 0000 0000 0000 0000 0000 0010 = + 2
  • Subtraction: use addition of negative numbers 0000 0000 0000 0000 0000 0000 0000 0011 = + 3 1111 1111 1111 1111 1111 1111 1111 1110 = - 2

Let’s do some excises!

Addition and Subtraction

0000 0000 0000 0000 0000 0000 0000 0101 = + 5 0000 0000 0000 0000 0000 0000 0000 0001 = + 1

Overflow

  • if result too large to fit in the finite computer word of the result register
    • e.g., adding two n-bit numbers does not yield an n-bit number 0111
  • 0001 1000
  • When the overflow can happen?
    • One positive+one negative?
    • Two positive/Two negative?