Data Representation By Surya and his Team #techwithsurya

Outline

Representing numbers

  • Unsigned

  • Signed

  • Floating point

Representing characters & symbols

  • ASCII
  • Unicode

Data Representation in Computers

  • Data are stored in Registers
  • Registers are limited in number & size

  • Range of n-bit register for unsigned value is 0 to 2^n-1.
  • Range of n-bit register for signed value is -2^n-1+1 to 2^n-1-1.

Data Representation 





Number System:

  • A Number system of base  or radix, r is a system that uses distinct symbols for r digits. 
  • Decimal number system(Base 10)
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • Binary number system(Base 2)
  • 0, 1
  • Octal number system(Base 8)
  • 0, 1, 2, 3, 4, 5, 6, 7
  • Hexadecimal number system(Base 16)
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Decimal

749.4=7*10^2+4*10^1+9*10^0+4*10^-1=700+40+9+0.4=749.4

Conversion between number system

  • decimal to binary
  • binary to decimal

Quantitative Numbers

Integers(Fixed-point Representation)

  • Unsigned
  • Signed

Non-integers(Floating-point Representation)

  • Floating point numbers - 10.25, 3.33333…, 1/8 = 0.125

1.Signed Integers

  • We need a way to represent negative values 

  • 3 representations

  1. Sign-Magnitude representation (S&M)
  2. 1’s Complement method
  3. 2’s Complement method

1. Sign-Magnitude Representation

  • n-bit unsigned magnitude & sign bit (S)
  • If MSB (Most Significant Bit) is-

  1. 0 – Integer is positive or zero 
  2. 1 – Integer is negative or zero

  • Range –2^n-1+1 to +(2n-1-1)

Example – Sign-Magnitude

  • If 8-bit register is used what are min & max  numbers?
  • What are 0000 0000 and 1000 0000 in decimal?

  1. Representation of zero is not unique
  2. -  2^(n-1)-1   to   + 2^(n-1) -1
  3. --127    to +127(8-bit)
  4. -7    to    +7(4-bit)
  5.  0,1…7,-0,-1…-7

Advantages

  • Sign reversal
  • Finding absolute value |a|
  • Flip sign bit

Disadvantage

  • Overflow of number 
  • Example
(a)
                      1010
                     +1110
                     11000 ( where 1 is overflow in binary number system)

(b)

                    010
                  +111
                   1101         
(c)
                      642
                    +321
                    1163( overflow in octal)

  • Adding a negative of a number is not the same as  subtraction

  1. e.g., add 2 and -3Need different operations 

  • Zero is not unique


2. Complement Method

  • Base = Radix

  1. Radix r system means r number of symbols
  2. e.g., binary numbers have symbols 0, 1

  • 2 types

  1. r’s complement (Radix/Base Component)
  2. (r – 1)’s complement (Diminished Radix/Base)
  3. Where r is radix (base) of number system

Examples

1.Decimal
2.Binary
3.9’s & 10’s complement
4. 1’s & 2’s complement

Definition

  • Given a number m in base/radix r & having n digits
  • (r – 1)’s complement of m is
  • (r^n– 1) – m
  • r ’s complement of m is
  • (r^n– 1) – m + 1= r^n– m
Example:

(a) If m = 5982 & n = 4 digits

  • 9’s complement is
    9 9 9 9
  5 9 8 2 
   4 0 1 7

  • 10’s complement 
                    or                 
1 0 0 0 0
   5 9 8 2 
4 0 1 8
   9 9 9 9
5 9 8 2
   4 0 1 7                
  +
 4 0 1 8

(b) If m = 382 & n = 3

n = 382 

 999                           1000
-382                           - 382
617                             618

-382 = 617 or 618
Depending on which complement we use
These are called complementary pair

(i) 1’s complement

Calculated by

(2n – 1) – m

If m = 0101

1’s complement of m on a 4-bit system 

1 1 1 1

0 1 0 1

1 0 1 0
1
1011(2’s Compliment)

This represents -5 in 1’s complement(1010).


Finding 1’s Complement – Short Cut

Loading..................

Addition with 1’s Complement

If results has a carry add it to LSB (Least  Significant Bit)

Example

Add 6 and -3 on a 3-bit system

         110

         100 

       1010
        +1
         011


2’s Complement

Doesn’t require end-around carry operation as in  1’s complement
2’s complement is formed by
Finding 1’s complement
Add 1 to LSB
New range is from -128 to +127
-128 because of +1 to negative value

Example

Pending 

Difference B/W 1s and 2s Complement. 

1’s complement has 2 zeros (+0, -0)
Value range is less than 2’s complement

2’s complement only has a single zero
Value range is unequal

No need of a separate subtract circuit
Doing a NOT operation is much more cost effective  in terms of circuit design
However, multiplication & division is slow.

Detecting Negative Numbers &  Overflow


  • Check for MSB
  • To find magnitude

1’s complement

Flip all bits

2’s complement

Flip all bits + 1

  • Rules to detect overflows in 2’s complement

If sum of 2 positive numbers yields a negative result,
sum has overflowed
If sum of 2 negative numbers yields a positive result,  sum has overflowed
Else, no overflow

 

Floating Point Numbers

  • We needed to represent fractional values &  values beyond 2n – 1
  • +3207.23 =3.20723*10^3
  • -0.000321=-3.21*10^-4
where -3=Sign
           21=mantissa
           10=Radix
           -4=Exponent 

Formula

N=m.r^e


IEEE Floating Point Standard (FPS)




 






PLEASE WAIT - WE WILL UPDATE THE POST WITH THE DIRECTION OF SATISH BANSAL SIR











Tech with Surya

TechWithSurya is a professional educational platform. Here we will provide you only interesting content, which you will love very much. We are dedicated to providing you with the best education possible with a focus on dependability, Mobile, Internet and Computer and technology. We are working to transform our passion for education into a fast growing online website. We hope you enjoy our education as much as we enjoy giving them to you.

1 Comments

  1. I’ve read quite a few student advice blogs, but your breakdown of how to handle academic stress is by far the most practical. It’s comforting to know that so many others face the exact same anxieties when deadlines pile up. For anyone who feels completely stuck and needs an extra hand to pull through a tough semester, looking into the best assessment help available can give you the competitive edge and peace of mind you need. Sometimes a little expert guidance is all it takes to turn a stressful week into a massive academic win.

    ReplyDelete
Post a Comment
Previous Post Next Post