Digital Representation

 Number System

  • Computers use binary (base 2) number system, as they are made from binary digital components known as transistors.
  • There are also hexadecimal (base 16) and octal (base 8) number systems.
Decimal (Base 10) Number System
  • It has ten symbols: 0-9, called digits.
  • It uses positional notation.
  • We can denote it with an optional suffix D if ambiguity arises.
Binary (Base 2) Number System
  • It also uses positional notation.
  • It has only 2 notations: 0 and 1.
  • We can denote it with the symbol B.
  • Eight bit is equal to a byte.
Hexadecimal (Base 16) Number System
  • It also uses positional notation.
  • It uses 16 symbols: 0-9 and A-F.
  • We can denote it with a suffix H.
  • Each hexadecimal digit is also called a hex digit.
  • Most programming language accept both lower case a-f and upper case A-F.

Number Representation-Unsigned

  • If there are N bits in the binary number, the range of the number is:
  • 0 .. 2 **N 1.  Assume 3 bits: 2**3- 1 = 8 -1=7
  • 000, 001, 010, 011
  • 100, 101, 110, 111
  • Range for 8 bits? 0..2 8 1 = 0..256 1=0..255
  • Why unsigned numbers?
  • Memory address, cluster number (file system) and process identifier (PID).

  • Each group of binary bits can be converted into a single hexadecimal digit.
Number Representation - Signed
  • For signed integers , the leftmost bit is used to indicate the sign
  • 0 for positive
  • 1 for negative
  • There are three ways to represent signed integers:
  • 1. Sign and magnitude
  • 2. 1’s complement
  • 3. 2’s complement                                                                                                                                   Negative numbers have different representations
  • Sign and magnitude: negative values are represented by changing the most significant bit (b 3)
  • 1’s complement: negative values are obtained by complementing each bit of the corresponding positive number.
  • 2’s complement: obtain by forming bit complement of that number, then add 1. 

Addition
There are four rules that need to be followed when adding two binary numbers. These
are:
0 + 0 = 0
1 + 0 = 1
1 + 1 = 10 (binary for 2)
1 + 1 + 1 = 11 (binary for 3)

Subtraction
Rules and tricks: Binary subtraction is much easier than the decimal subtraction when
you remember the following rules:
0-0 = 0
1-0 = 1
1-1 = 0
0-1 = 1 (Borrow 1)

For signed integers, the leftmost bit is used to indicate the sign:
  • 0 for positive
  • 1 for negative
  • Range: -2**n**(- 1) to +2**n**(-1)- 1
  • 4 bits: -8 to 7 (2**3 to 2**3**(-1)) , 8 bits: -128 to 127 (2**7 to 2**7**(-1))
OVERFLOW occurs when the answer does not fir in the number range.

Overflow (Addition)
●If 2 Two's Complement numbers are added, and they both have the same sign (both
positive or both negative), then overflow occurs if and only if the result has the
opposite sign.
●Overflow never occurs when adding operands with different signs.
  • Adding two positive numbers must give a positive result
  • Adding two negative numbers must give a negative result
Overflow occurs if:
(+A) + (+B) = −C
(−A) + (−B) = +C

Overflow (Subtraction)
●If 2 Two's Complement numbers are subtracted, and their signs are different, then
overflow occurs if and only if the result has the same sign as the subtrahend (what is
being subtracted).
●Overflow occurs if

(+A) − (−B) = −C
(−A) − (+B) = +C

Comments

Popular posts from this blog

Topic D02 Introduction to Linux

EO2-Linux Network and Process Managment

Topic D01- Container Technology