Difference between revisions of "Data Representations"

From AstroBaki
Jump to navigationJump to search
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
===Prerequisites===
 
 
None
 
 
 
===Short Topical Videos===
 
===Short Topical Videos===
 
 
*  [http://www.youtube.com/watch?v=-WNkBkIE560| (Computer) Data Types and Representations, Part I (by Aaron Parsons)]
 
*  [http://www.youtube.com/watch?v=-WNkBkIE560| (Computer) Data Types and Representations, Part I (by Aaron Parsons)]
 
*  [http://www.youtube.com/watch?v=KsKWwtBJjGw| (Computer) Data Types and Representations, Part II (by Aaron Parsons)]
 
*  [http://www.youtube.com/watch?v=KsKWwtBJjGw| (Computer) Data Types and Representations, Part II (by Aaron Parsons)]
  
 
===Reference Material===
 
===Reference Material===
 +
*  [http://en.wikipedia.org/wiki/ASCII ASCII reference]
 +
*  [http://en.wikipedia.org/wiki/Floating_point Floating-point reference]
 +
*  [http://en.wikipedia.org/wiki/Fixed-point_arithmetic Fixed-point reference]
 +
 +
<latex>
 +
\documentclass[11pt]{article}
 +
\setlength\parindent{0 in}
 +
\setlength\parskip{0.1 in}
 +
\usepackage{fullpage}
 +
\usepackage{amsmath}
 +
\usepackage{graphicx}
 +
 +
\begin{document}
 +
\title{Bits, Bytes, and Beyond}
 +
\section{The Binary Point}
 +
 +
In decimal, a number is formulated by multiplying each character by a power of 10. We know which number is multiplied by $10^0$ because it lies immediately to the left of the decimal point, for example:
 +
\begin{align}
 +
462.15 &= 4\times10^2 + 6\times10^1 + 2\times10^0 + 1\times10^{-1} + 5\times10^{-2}\\
 +
    &= 400+60+2+ 1\frac1{10} + \frac5{100}\\
 +
    &= 462.15\\
 +
\end{align}
 +
In binary, the number multiplied by $2^0$ lies immediately to the left of the {\it binary point}:
 +
\begin{align}
 +
101.01 &= 1\times2^2 + 0\times2^1 + 1\times2^0 + 0\times2^{-1} + 1\times2^{-2}\\
 +
      &= 4+0+1+\frac02+\frac14\\
 +
      &= 5.25 ({\rm in\ decimal})\\
 +
\end{align}
 +
When programming for FPGAs, we often need to know the specifics of a number, namely how many bits it is made up of and where the binary point lies. Simulink displays this information using the format n\_m, where n is the bit width of the number and m is how many bits lie to the right of the binary point. For example, 101.01 would be a 5\_2 number. A data type is called {\it fixed-point} when the binary point is fixed in one location.
 +
 +
\section{Unsigned vs. Signed Representations}
 +
In mathematics, we represent a negative number by adding a '-' character
 +
to the front of it. A computer deals
 +
only with 0's and 1's,
 +
so it must use another
 +
method. One solution is to simply use the most-significant bit to represent the sign, a method known as sign-magnitude.  This method has problems: the
 +
number zero is represented twice (+0 and -0 have different representations), and adders and subtracters require extra circuitry to handle negative numbers.
 +
 +
A better solution is a method known as two's complement.  This is what most computers use. To negate a number in this system, you invert the number
 +
bitwise (change 1's to 0's and vice versa) and then add 1 to result. The result of these rules is that the "higher half" of the unsigned numbers wrap around and
 +
become the negative numbers. With 3 bits, we have:
 +
\begin{table}[!ht]
 +
\begin{tabular}{r|rrrrrrrr}
 +
&000&001&010&011&100&101&110&111\\
 +
\hline
 +
unsigned& 0& 1& 2& 3& 4& 5& 6& 7\\
 +
sign-magnitude& 0&  1&  2&  3&  -0& -1& -2& -3\\
 +
two's complement&  0&  1&  2&  3&  -4& -3& -2& -1\\
 +
\end{tabular}
 +
\end{table}
 +
 +
Note that the two's complement system only represents zero once. What's more, adding and subtracting two's complement numbers the normal way (as if
 +
they were unsigned) produces the correct result. In Simulink, only unsigned and two's complement numbers are supported.
  
*  [http://en.wikipedia.org/wiki/ASCII| ASCII reference]
+
\end{document}
*  [http://en.wikipedia.org/wiki/Floating_point| Floating-point reference]
+
</latex>
*  [http://en.wikipedia.org/wiki/Fixed-point_arithmetic| Fixed-point reference]
 

Latest revision as of 22:12, 27 September 2012

Short Topical Videos[edit]

Reference Material[edit]

Bits, Bytes, and Beyond

1 The Binary Point

In decimal, a number is formulated by multiplying each character by a power of 10. We know which number is multiplied by because it lies immediately to the left of the decimal point, for example:

In binary, the number multiplied by lies immediately to the left of the binary point:

When programming for FPGAs, we often need to know the specifics of a number, namely how many bits it is made up of and where the binary point lies. Simulink displays this information using the format n_m, where n is the bit width of the number and m is how many bits lie to the right of the binary point. For example, 101.01 would be a 5_2 number. A data type is called fixed-point when the binary point is fixed in one location.

2 Unsigned vs. Signed Representations

In mathematics, we represent a negative number by adding a ’-’ character to the front of it. A computer deals only with 0’s and 1’s, so it must use another method. One solution is to simply use the most-significant bit to represent the sign, a method known as sign-magnitude. This method has problems: the number zero is represented twice (+0 and -0 have different representations), and adders and subtracters require extra circuitry to handle negative numbers.

A better solution is a method known as two’s complement. This is what most computers use. To negate a number in this system, you invert the number bitwise (change 1’s to 0’s and vice versa) and then add 1 to result. The result of these rules is that the "higher half" of the unsigned numbers wrap around and become the negative numbers. With 3 bits, we have:

000

001

010

011

100

101

110

111

unsigned

0

1

2

3

4

5

6

7

sign-magnitude

0

1

2

3

-0

-1

-2

-3

two’s complement

0

1

2

3

-4

-3

-2

-1

Note that the two’s complement system only represents zero once. What’s more, adding and subtracting two’s complement numbers the normal way (as if they were unsigned) produces the correct result. In Simulink, only unsigned and two’s complement numbers are supported.