data representation notes

© All Rights Reserved

5 views

data representation notes

© All Rights Reserved

- Collection of String Programs using Recursion [First Edition]
- Socha, Norton-Assembly Language for the PC-3rd Edition-1992
- Beginning Assembly for the TI
- EASA PART 66 GUIDE_ EASA Part 66 _ Digital Question.pdf
- PLC Connection Guide
- Programming Using c++
- Communications Manual R300 603 100
- Beginning Programming in C
- numarical metoud Lecture 01
- Interfacing Hex Keypad to 8051.
- ABAP Programming : Tips & Tricks
- Decimal - Binary - Hex Conversion Sheet - Examples
- FPU
- Dsp Lab Manual
- Digital Number System
- Changing Emissivity MLX90614xxx
- Microcontrollers+Lab+Manual
- Floating Point Representation
- Little Book of Java
- Floating_Point_FPGA

You are on page 1of 11

---------------------------------

transistors).

possible qualifications:

1. positive numbers only

2. positive and negative numbers

3. ease of human readability

4. speed of computer operations

All have been used at various times for various reasons.

1. unsigned

2. sign magnitude

3. one's complement

4. two's complement

5. biased (not commonly known)

representation. why?

1. hardware is faster

2. hardware is simpler (which makes it faster)

UNSIGNED

--------

the standard binary encoding already given

n=4, 2**4 -1 is 15

0000 0 0 1000 8 8

0001 1 1 1001 9 9

0010 2 2 1010 10 a

0011 3 3 1011 11 b

0100 4 4 1100 12 c

0101 5 5 1101 13 d

0110 6 6 1110 14 e

0111 7 7 1111 15 f

SIGN MAGNITUDE

--------------

The hw that does arithmetic on sign magnitude integers

is not fast, and it is more complex than the hw that does arithmetic

on 1's comp. and 2's comp. integers.

1 be negative.

as unsigned integers

example: 4 bits

0101 is 5

1101 is -5

(not, invert, complement, negate) the sign bit.

where n is the number of bits

4 bits, -7 to +7

n=4, - 2**3 + 1 to 2**3 - 1

-8 + 1 to 8 - 1

This is a problem for hardware. . .

0000 is 0, 1000 is 0

the computer must do all calculations such that they

come out correctly and the same whichever representation is used.

ONE's COMPLEMENT

----------------

2's complement integers.

Now, nobody builds machines that are based on 1's comp. integers.

In the past, early computers built by Semour Cray (while at CDC)

were based on 1's comp. integers.

00000 is 0

00111 is 7, etc.

complement of the positive representation.

a logical operation done on a single bit

the complement of 1 is 0.

the complement of 0 is 1.

complement each bit 11110

that is -1.

to find out which, find the additive

inverse!

00011 is +3 by sight,

so 11100 must be -3

2. there are 2 representations for 0,

00000 and 11111.

TWO's COMPLEMENT

----------------

0. This makes the hardware that does arithmetic faster than for the

other representations.

a 3 bit example:

bit pattern: 100 101 110 111 000 001 010 011

1's comp: -3 -2 -1 0 0 1 2 3

2's comp.: -4 -3 -2 -1 0 1 2 3

the negative values are all "slid" down by one, eliminating the

extra zero representation.

positive values are the same as for sign/mag and 1's comp.

they will have a 0 in the MSB (but it is NOT a sign bit!)

negative:

take the positive value 00101 (+5)

take the 1's comp. 11010 (-5 in 1's comp)

add 1 + 1

------

11011 (-5 in 2's comp)

1. take the 1's comp.

2. add 1

start at LSB, for each bit (working right to left)

while the bit is a 1, change it to a 0.

when a 0 is encountered, change it to a 1 and stop.

the rest of the bits remain the same as they were.

EXAMPLE:

what decimal value does the two's complement 110011 represent?

is a 1. Therefore, find the additive inverse:

+ 1

------

001101 (2's comp. +13)

----------------------

we'll see how to really do this in the next chapter, but here's

a brief overview.

0 0 0 0 0

0 0 1 1 0

0 1 0 1 0

0 1 1 0 1

1 0 0 1 0

1 0 1 0 1

1 1 0 0 1

1 1 1 1 1

a 0011

+b +0001

-- -----

sum 0100

0 + 0 = 0

1 + 0 = 1

1 + 1 = 2 which is 10 in binary, sum is 0 and carry the 1.

1 + 1 + 1 = 3 sum is 1, and carry a 1.

BIASED REPRESENTATION

---------------------

look just like unsigned but actually represent negative numbers.

add in the bias +8

----

unsigned value 11

will be 1011

biased-8 representation as 0110

subtract out the bias - 8

----

TRUE VALUE represented -2

to be the same as for unsigned integers, but actually represents

both positive and negative values.

choosing a bias:

the bias chosen is most often based on the number of bits

available for representing an integer. To get an approx.

equal distribution of true values above and below 0,

the bias should be 2 ** (n-1) or (2**(n-1)) - 1

SIGN EXTENSION

--------------

how to change an integer with a smaller number of bits into the

same integer (same representation) with a larger number of bits.

go over it.

by representation:

unsigned: xxxxx --> 000xxxxx

copy the original integer into the LSBs, and put 0's elsewhere

copy the original integer's magnitude into the LSBs,

put the original sign into the MSB, and put 0's elsewhere

copy the original integer into the LSBs,

take the MSB of original integer and copy it elsewhere.

example: 0010101

000 0010101

11110000

11111111 11110000

OVERFLOW

--------

of bits allowed. Examples:

unsigned, 3 bits: 8 would require at least 4 bits (1000)

sign mag., 4 bits: 8 would require at least 5 bits (01000)

we say that overflow has occurred. Overflow occurs when doing

arithmetic operations.

011 (3)

+ 110 (6)

---------

? (9) it would require 4 bits (1001) to represent

the value 9 in unsigned rep.

CHARACTER REPRESENTATION

------------------------

We use standard encodings (binary sequences) to repreesent characters.

A standard code ASCII (American Standard for Computer Information

Interchange) defines what character is represented by each sequence.

examples:

0100 0001 is 41 (hex) or 65 (decimal). It represents `A'

0100 0010 is 42 (hex) or 66 (decimal). It represents `B'

that needs to be represented.

The code has some nice properties. If the bit patterns are compared,

(pretending they represent integers), then `A' < `B'

This is good, because it helps with sorting things into alphabetical

order.

`8' (38 hex) is different than the integer 8

the digits:

`0' is 48 (decimal) or 30 (hex)

`9' is 57 (decimal) or 39 (hex)

Because of this, code must deal with both characters and integers

correctly.

in1 db ?

result db ?

get_ch in1

moveb result, in1

iadd result, in1

put_ch result

result <- 51 + 51 = 102 (decimal)

put_ch prints out `f', since the ASCII code for 102(decimal) is `f'

to the integers they represent, and visa versa.

result.

the steps:

read `3'

translate `3' to 3

read `5'

translate `5' to 5

integer = 3 * 10 + 5 = 35

read `4'

translate `4' to 4

integer = 35 * 10 + 4 = 354

the algorithm:

integer = 0

while there are more characters

get character

digit <- character - 48

integer <- integer * 10 + digit

dealing with printing out integers.

the steps:

for 354 (an integer), figure out how many characters there are (3)

translate 3 to `3' and print it out

354 mod 100 gives 54

54 div 10 gives 5

translate 5 to `5' and print it out

54 mod 10 gives 4

4 div 1 gives 4

translate 4 to `4' and print it out

4 mod 1 gives 0, so you're done

NOTE: These algorithms work the same in bases other than 10.

Just change the 10 to the desired base. (There is some extra

work in bases > 10, since have to translate the digits > 9

into the characters. For example, 12 (decimal) is c (hex).)

----------------------------------------

scientific notation. There are standards which define what the

representation means so that across computers there will be consistancy.

Note that this is not the only way to represent floating point

numbers, it is just the IEEE standard way of doing it.

Here's what we do:

the representation

-------------------

| S | E | F |

-------------------

E is an 8 bit biased integer representing the exponent

F is an unsigned integer

S e

(-1) x f x 2

where

e = E - bias

n

f = F/2 + 1

n = 23

bias = 127

IEEE single precision floating point representation.)

--> S, E, F all represent fields within a representation. Each

is just a bunch of bits.

So, the true exponent represented is (E - bias). The radix for

the number is ALWAYS 2.

Note: Computers that did not use this representation, like those

built before the standard, did not always use a radix of 2.

Example: some IBM machines had radix of 16.

23 bits available for the mantissa. It turns out that if fl. pt.

numbers are always stored in a normalized form, then the leading

bit (the one on the left, or MSB) is always a 1. So, why store

it at all? It gets put back into the number (giving 24 bits

of precision for the mantissa) for any calculation, but we only have

to store 23 bits.

An example: put the decimal number 64.2 into the IEEE single

precision representation.

first step:

get a binary representation for 64.2

to do this, get binary reps. for the stuff to the left

and right of the decimal point separately.

64 is 1000000

.2 x 2 = 0.4 0 (msb)

.4 x 2 = 0.8 0

.8 x 2 = 1.6 1

.6 x 2 = 1.2 1

.4 x 2 = 0.8 0

.8 x 2 = 1.6 1

.6 x 2 = 1.2 1

64.2 is 1000000.0011001100110011. . .

second step:

normalize the binary representation. (make it look like

scientific notation)

6

1.000000 00110011. . . x 2

third step:

6 is the true exponent. For the standard form, it needs to

be in biased-127 form.

6

+ 127

-----

133 (value of biased exponent)

fourth step:

the mantissa stored (F) is the stuff to the right of the radix point

in the normal form. We need 23 bits of it.

000000 00110011001100110

S E F

0 10000101 00000000110011001100110

0x 4 2 8 0 6 6 6 6

or

42806666h

form, how do we represent 0?

(What does the fl. pt. number 0x0080 0000 represent?)

to represent the value 0.

-infinity 1 11111111 00000... (0xff80 0000)

(S is either 0 or 1, E=0xff, and F is anything but all zeros)

- Collection of String Programs using Recursion [First Edition]Uploaded byGuide For School
- Socha, Norton-Assembly Language for the PC-3rd Edition-1992Uploaded byMostitt
- Beginning Assembly for the TIUploaded byMike Price
- EASA PART 66 GUIDE_ EASA Part 66 _ Digital Question.pdfUploaded bySéanagh Ní Bheacháin
- PLC Connection GuideUploaded bySara Caldwell
- Programming Using c++Uploaded bykumartalentavinash
- Communications Manual R300 603 100Uploaded bydhlinh
- Beginning Programming in CUploaded byJeffrey Abadesa Esmundo
- numarical metoud Lecture 01Uploaded byalula
- Interfacing Hex Keypad to 8051.Uploaded byRejin
- ABAP Programming : Tips & TricksUploaded bykattak2k
- Decimal - Binary - Hex Conversion Sheet - ExamplesUploaded byHussein Meniawy
- FPUUploaded bySatya Narayanan
- Dsp Lab ManualUploaded byMadhan Reddy
- Digital Number SystemUploaded byNicholas Sawe
- Changing Emissivity MLX90614xxxUploaded byRicardo Magallán
- Microcontrollers+Lab+ManualUploaded byArati Daz
- Floating Point RepresentationUploaded byPulkit Gupta
- Little Book of JavaUploaded byjeep2014
- Floating_Point_FPGAUploaded byTudor Cret
- verilog_lec.pdfUploaded bykamss
- ch2Uploaded byNajibul adib
- ITC PresentationUploaded byapi-3713097
- TeX Program BookUploaded byHercudonX
- TexUploaded byTendai M Mudziiri Shumba
- TCLWikibookUploaded bycyzyjy
- bilal (1)Uploaded byBilal Hussain Shah
- 3 - Problem Solving Through Flowcharts 2Uploaded byJoey Lazarte
- Prorams on OperatorsUploaded byVenkata Ranga Rao
- Lecture 232Uploaded byFreedom Storm

- Computer CrimeUploaded byAgrippa Mungazi
- Unified Modelling LanguageUploaded byAgrippa Mungazi
- CctvUploaded byAgrippa Mungazi
- twin prime numbers.docxUploaded byAgrippa Mungazi
- ANALYSIS.xlsxUploaded byAgrippa Mungazi
- Algorithm Bubble SortUploaded byAgrippa Mungazi
- Benefits of business plan.docxUploaded byAgrippa Mungazi
- routingUploaded byAgrippa Mungazi
- Comments in ProgrammingUploaded byAgrippa Mungazi
- ArraysUploaded byAgrippa Mungazi
- Standard AlgorithmsUploaded byAgrippa Mungazi
- BubbleSort AlgorithmUploaded byAgrippa Mungazi
- Addressing ModesUploaded byAgrippa Mungazi
- IP Addressing 02Uploaded byAgrippa Mungazi
- Validation CodesUploaded byAgrippa Mungazi
- My Code for Saving DataUploaded byAgrippa Mungazi
- Use ICTUploaded byAgrippa Mungazi
- Cyber CultureUploaded byAgrippa Mungazi
- MemoryUploaded byAgrippa Mungazi
- Binary NotationUploaded byAgrippa Mungazi
- List of Terms Used in a MicroprocessorUploaded byAgrippa Mungazi
- Computer SecurityUploaded byAgrippa Mungazi
- General Purpose PackagesUploaded byAgrippa Mungazi
- Fundamentals of ProgrammingUploaded byAgrippa Mungazi
- What is SDLC or Waterfall ModelUploaded byAgrippa Mungazi

- 23-1-11Uploaded byMurali Krishna
- Decimal to Binary ConversionUploaded byKiran Chaudhary
- IP Address Calculation (Daliilatul Diyanah Bt Yatiman)Uploaded byDyla Diyanah
- Number Systems and CodesUploaded byBijay Mishra
- MIT6_045JS11_lec09Uploaded byMuhammad Al Kahfi
- Algorithms and Resource RequirementsUploaded byrananaveedkhalid
- Floating Point Arithmetic Unit Using VerilogUploaded bynamdt1
- RECINF221SA67614.docUploaded byJairo Benjamín Huanca Crespo
- theory.docxUploaded bybhatiaharryjassi
- NI Tutorial 3115 en (1)Uploaded byajith.ganesh2420
- Conversion DFA to Regular ExpressionUploaded bydisismandii
- DMRC Junior Engineering Question PaperUploaded bySunil Kumar
- 6 - 2 - 21. Satisfiability and Cook's Theorem (44 Min.)Uploaded byHuong Luong
- Lecture on DFA to REUploaded byਕੁਲਵਿੰਦਰ ਸਿੰਘ
- Cbazgan EnUploaded byYassine Bouigua
- Intractable PptUploaded byGauri
- MancalaUploaded byAjay Malalikar
- Class WorkUploaded bySafia Amir Dahri
- Digital BasicsUploaded byshrish9999
- 08-Unit8Uploaded byJohn Arthur
- ch08_seg2101_-_lexical_analysis (1).pptUploaded byHuỳnh Đức
- Foundations of Mathematics Lecture NotesUploaded bytheSuha
- TocUploaded byHari
- Automata Theory ApplicationsUploaded byKelvin
- GATE - CS - Digital LogicUploaded byAnonymous 8pCXXs
- Experiment-10 (Adder & Subtractor)Uploaded byM Balaji
- COMPE 271Fall2013Mid1- SolutionUploaded bycp733
- Solution FaUploaded bykazi wahex
- class0Uploaded byAmmad Talib
- Practice 1Uploaded byBob Brawyn