Top Banner
Data Representation Alexander Nelson September 16, 2019 University of Arkansas - Department of Computer Science and Computer Engineering
18

Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

May 31, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Data Representation

Alexander Nelson

September 16, 2019

University of Arkansas - Department of Computer Science and Computer Engineering

Page 2: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Digital Representation

Digital – Discrete, discontinuous representation of information

i.e. [..., -100, -99, ..., 0, 1, 2, 3, ..., 100, 101, ...]

Contrasted with Analog – Continuous signal

i.e. Soundwave

1

Page 3: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Analog vs. Digital

12

827863

39

70

44

9

-36

-69-80

-59

-14

42

Analog

Digital

Digital can be used to approximate analog signals

Some loss of precision

2

Page 4: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Digital Representation

Why digital for computation?

• Store data

• Logic – Binary

• Reconfigurable/Programmable

• Noise/Error Correction

3

Page 5: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Binary Representation

Binary – 0 or 1 – Building block of digital systems

Single binary values (bits) linked together to create larger

abstractions

How are bits stored/transmitted?

4

Page 6: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Binary Encoding

How are binary values encoded in hardware?

Transistor Compact Disc Flash Memory

Find high reliability method of differentiating between digital 0 and

digital 1

5

Page 7: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Digital Wireless Communication

Radio waves are analog, how are they converted to digital?

Amplitude

Modification (AM)

Frequency

Modification (FM)

Phase Modification

6

Page 8: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Braille

Braille - 6 bit alphabetical representation

7

Page 9: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Byte Representation

Computer Architectures started to use 8-bit bytes as the basic

storage size

Popularized by 1970s microprocessors (Intell 8008, predecessor of

the 8080 and 8086)

Arithmetic units/registers increased number of bits, but

terminology of the Byte stuck

8

Page 10: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Byte Representation

A byte can represent 256 discrete values

Can represent any 256 values determined by programmer

To take advantage of logic, usually linearly continuous so adder

circuits work

Many exceptions, including ASCII

’A’ + ’C’ == ?

9

Page 11: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Base 10 Representation

Humans tend to think in a Base 10 numerical system

10

Page 12: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Base 10 Representation

Generates overhead when displaying numbers to humans

atoi() – C function to convert from ascii to integers

itoa() – C function to convert from integers to ascii

11

Page 13: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

atoi()

// A simple atoi() function

int myAtoi(char *str){

int res = 0; // Initialize result

int sign = 1; // Initialize sign as positive

int i = 0; // Initialize index of first digit

// If number is negative, then update sign

if (str[0] == ’-’){

sign = -1;

i++; // Also update index of first digit

}

// Iterate through all digits and update the result

for (; str[i] != ’\0’; ++i)

res = res*10 + str[i] - ’0’;

// Return result with sign

return sign*res;

}12

Page 14: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Base Conversion Overhead

How much memory does the integer 123,456,789 consume?

How much memory does the ASCII representation of 123,456,789

consume?

Assume a string encoded integer is input into your system, you

wish to perform some arithmetic on that integer, then output the

string to another system. What is the overhead associated with

this task?

13

Page 15: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Hexadecimal

Why are byte values often given as hexadecimal (base 16) if

conversion has overhead

Converting from base 2 to base 2x for printing is quick (shifts)

Readability is similar to decimal.

14

Page 16: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Precision

Precision of a number depends on width of the storage(in bits),

and the variability of the quantity being measured

Going beyond that number causes overflow/underflow

15

Page 17: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Signed/Unsigned

Keep up with the signed/unsigned nature of values

Representation between systems should be documented to prevent

miscalculation

This includes type of sign (e.g. Sign bit, one’s complement, two’s

complement)

16

Page 18: Data Representation - University of Arkansascsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture7.pdf · Data Representation Alexander Nelson September 16, 2019 University of Arkansas

Text

Text is stored in C using ASCII (which we have already covered)

In practice, may need to store more than Roman characters

Unicode – Character set with ∼120,000 characters

Commonly used Unicode Schemes: UTF-8, UTF-16, UTF-32

17