Number Systems and Binary Representation in Computer Architectures, Study notes of Digital & Analog Electronics

An introduction to number systems, focusing on binary representation and its conversions to decimal and hexadecimal. It covers positional notation, common powers, binary to decimal and hex to decimal conversions, and the representation of binary numbers in hexadecimal format. The document also explains how to convert binary numbers to decimal and hexadecimal.

Typology: Study notes

2010/2011

Uploaded on 09/02/2011

hamit1990
hamit1990 🇮🇳

4.3

(76)

95 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Number System
Microprocessor Computer Architectures Lab
Binary Representation
The basis of all digital data is binary representation.
Binary - means ‘two’
1, 0
True, False
Hot, Cold
On, Off
We must be able to handle more than just two values for real world
problems
1, 0, 5
True, False, Maybe
Hot, Cold, Lukewarm, Cool
On, Off, Leaky
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Number Systems and Binary Representation in Computer Architectures and more Study notes Digital & Analog Electronics in PDF only on Docsity!

Binary Representation

  • (^) The basis of all digital data is binary representation.
  • (^) Binary - means ‘two’
    • (^) 1, 0
    • (^) True, False
    • (^) Hot, Cold
    • (^) On, Off
  • (^) We must be able to handle more than just two values for real world problems - (^) 1, 0, 5 - (^) True, False, Maybe - (^) Hot, Cold, Lukewarm, Cool - (^) On, Off, Leaky

Number Systems

• To talk about binary data, we must first talk about

number systems

• The decimal number system (base 10) you should

be familiar with

  • (^) A digit in base 10 ranges from 0 to 9.
  • (^) A digit in base 2 ranges from 0 to 1 (binary number system). A digit in base 2 is also called a ‘bit’.
  • (^) A digit in base R can range from 0 to R-
  • (^) A digit in base 16 can range from 0 to 16- (0,1,2,3,4,5,5,6,7,8,9,A,B,C,D,E,F). Use letters A-F to represent values 10 to 15. Base 16 is also called Hexadecimal or just ‘Hex’.

Base 10, Base 2, Base 16

The textbook uses subscripts to represent different bases (ie. A2F 16 , 953.78 10 , 1011.11 2 )

Special symbols can be used to represent the different bases. The default base will be decimal, no special symbol for base 10.

The ‘$’ will be used for base 16 ( $A2F) Will also use ‘h’ or ‘H’ at end of number (A2Fh, A2FH)

The ‘%’ will be used for base 2 (%10101111)

Common Powers

Conversion of Decimal To ANY Base

Divide Number N by base R until quotient is 0. Remainder at EACH step is a digit in base R, from Least Significant digit to Most Significant digit.

Convert 53 to binary 53/2 = 26, rem = 1 26/2 = 13, rem = 0 13/2 = 6, rem = 1 6 /2 = 3, rem = 0 3/2 = 1, rem = 1 1/2 = 0, rem = 1

53 = % 110101 = 1x2^5 + 1x2^4 + 0x2^3 + 1x2^2 + 0x2^1 + 1x2^0 = 32 + 16 + 0 + 4 + 0 + 1 = 53

Least Significant Digit

Most Significant Digit

Least Significant Digit, Most Significant Digit

Most Significant Digit (has weight of 2^5 or 32). For base 2, also called Most Significant Bit (MSB). Always LEFTMOST digit.

Least Significant Digit (has weight of 2^0 or 1). For base 2, also called Least Significant Bit (LSB). Always RIGHTMOST digit.

Hex to Binary Conversion

Each Hex digit represents 4 bits. To convert a Hex number to Binary, simply convert each Hex digit to its four bit value.

  • 2 -3 = 0.
  • 2 -2 = 0.
  • 2 -1 = 0.
  • 20 =
  • 21 =
  • 22 =
  • 23 =
  • 24 =
  • 25 =
  • 26 =
  • 27 =
  • 28 =
  • 29 =
  • 210 =
  • 211 =
  • 212 = - 160 = 1 = - 161 = 16 = - 162 = 256 = - 163 = 4096 =
    • 220 = 1048576 = 1 M (1 Megabits) = 1024 K = 2^10 x 210 = 1024 = 1 K
  • $ 0 = % Hex Digits to binary:
  • $ 1 = %
  • $ 2 = %
  • $ 3 = %
  • $ 4 = %
  • $ 5 = %
  • $ 6 = %
  • $ 7 = %
  • $ 8 = %
    • $ 9 = %
    • $ A = %
    • $ B = %
    • $ C = %
    • $ D = %
    • $ E = %
    • $ F = %

Hex to Binary, Binary to Hex

A2Fh = % 1010 0010 1111

345h = % 0011 0100 0101

Binary to Hex is just the opposite, create groups of 4 bits starting with least significant bits. If last group does not have 4 bits, then pad with zeros for unsigned numbers.

% 1010001 = % 0101 0001 = 51h

Padded with a zero

Binary Numbers Again

Recall than N binary digits (N bits) can represent unsigned

integers from 0 to 2N-1.

4 bits = 0 to 15 8 bits = 0 to 255 16 bits = 0 to 65535

Besides simply representation, we would like to also do arithmetic operations on numbers in binary form. Principle operations are addition and subtraction.

Binary Arithmetic, Subtraction

The rules for binary arithmetic are:

0 + 0 = 0, carry = 0 1 + 0 = 1, carry = 0 0 + 1 = 1, carry = 0

1 + 1 = 0, carry = 1

The rules for binary subtraction are:

0 - 0 = 0, borrow = 0 1 - 0 = 1, borrow = 0 0 - 1 = 1, borrow = 1

1 - 1 = 0, borrow = 0

Borrows, Carries from digits to left of current digit. Binary subtraction, addition works just the same as decimal addition, subtraction.

Subtraction

Decimal

900

  • 001

899 

0-1 = 9; with borrow of 1 from next column 0 -1 (borrow) - 0 = 9, with borrow of 1 9 - 1 (borrow) - 0 = 8. Answer = 899.

Binary

% 100

  • % 001

     011 

0-1 = 1; with borrow of 1 from next column 0 -1 (borrow) - 0 = 1, with borrow of 1 1 - 1 (borrow) - 0 = 0. Answer = % 011.

Hex Addition

3Ah

  • 28h

62h

A+8 = 2; with carry out of 1 to next column

1 (carry) + 3 + 2 = 6. answer = $ 62.

3Ah = 3 x 16 + 10 = 58 28h = 2 x 16 + 8 = 40 58 + 40 = 98

62h = 6 x 16 + 2 = 96 + 2 = 98!

Decimal check.

Fixed Precision

With paper and pencil, we can write a number with as many digits as we want:

1,027,80,032,034,532,002,391,030,300,209,399,302,992,092,

A microprocessor or computing system usually uses FIXED PRECISION for integers; they limit the numbers to a fixed number of bits:

$ AF4500239DEFA231 64 bit number, 16 hex digits $ 9DEFA231 32 bit number, 8 hex digits $ A231 16 bit number, 4 hex digits $ 31 8 bit number, 2 hex digits

High end microprocessors use 64 or 32 bit precision; low end microprocessors use 16 or 8 bit precision.

Unsigned Overflow

In this class we will use 8 bit precision most of the time, 16 bit occasionally.

Overflow occurs when we add or subtract two numbers, and the correct result is a number that is outside of the range of allowable numbers for that precision. We can have both unsigned and signed overflow (more on signed numbers later)

8 bits -- unsigned integers 0 to 2^8 -1 or 0 to 255.

16 bits -- unsigned integers 0 to 2^16 -1 or 0 to 65535