\documentstyle[11pt,psfig,aaspp4]{article}
\begin{document}
\title{\bf QUICK IDL TUTORIAL NUMBER TWO: IDL DATATYPES \\ \today}
\section{ DIGITS, BITS, BYTES, AND WORDS}
We have gotten to the place where you need to know a little
about the internal workings of computers. Specifically, how the computer
stores numbers and characters.
Humans think of numbers expressed in powers-of-ten, or {\it
decimal numbers}. This means that there are 10 digits $(0 \rightarrow
9)$ and you begin counting with these digits. When you reach the
highest number expressible by a single digit, you use two digits and
generate the next series of numbers, $10 \rightarrow 99$. Let $f$ and
$s$ be the {\it first} and {\it second} digits, respectively; then the
number is $10^f + s$. And so on with more digits.
Fundamentally, all computer information is stored in the form of
{\it binary numbers}, meaning powers-of-two. How many digits? Two! They
are 0 and 1. The highest number expressible by a single digit is 1.
The two-digit numbers range from 10 to 11; the number is $2^f + s$. And
so on with more digits. But wait a minute! The word ``digit'' is a
misnomer---it implies something about 10 fingers. Here it's the word
{\bf bit} that counts. Each binary ``digit'' is really a {\bf bit}. So
the binary number 1001 is a 4-bit number. What decimal number does the
binary number 1001 equal?
For convenience, computers and their programmers group the bits
into groups of eight. Each group of 8 bits is called a {\bf byte}.
Consider, then, the binary number 11111111; it's the maximum-sized
number that can be stored in a byte. What is this number?
Finally, computers group the bytes into {\bf words}. The oldest
PC's dealt with 8-bit words---one btye. The Pentiums and Sparcs deal
with 32-bit words---four bytes. What's the largest number you can store
in a 4-byte word? And how about negative numbers?
Below we describe how IDL (and everybody else) gets around this
apparent upper limit on numbers. They do this by defining different
data types. Up to now, the details didn't matter much. But now\dots We
don't cover all datatypes below---specifically, we omit Complex (yes,
complex numbers!), Hexadecimal, Octal, and Structure datatypes, which
you can look up if you are interested.
\section {INTEGER DATATYPES IN IDL}
{\it Integer} datatypes store the numbers just like you'd
expect. IDL supports integers of four different lengths: 1, 2, 4, and 8
bytes. The shorter the word, the less memory required; the longer the
word, the larger the numbers can be. Different requirements require
different compromises.
\subsection {1 byte: The Byte Datatype}
The Byte datatype is a single byte long and always positive.
Therefore, its values run $0 \rightarrow 255$. Images are always
represented in bytes. The {\it data} might not be in bytes, but the
numbers that the computer sends to the video processor card are always
bytes. Video screens require lots of memory and really quick processing
speed, so bytes are ideal. You generate an array using {\bf bindgen};
you can generate a single byte variable by saying {\bf
x=3b}. If, during a calculation, a byte number exceeds 255, then it
will ``wrap around''; for example, 256 wraps to 0, 257 to 1, etc.
\subsection{2 bytes: Integers and Unsigned Integers}
With 2 bytes, numbers that are always positive are called {\bf
Unsigned Integers}. They can range from $0 \rightarrow 256^2 -1$, or $0
\rightarrow 65535$. You generate an array using {\bf uindgen}. How do
you think unsigned integers wrap around?
Normally you want the possibility of negative numbers and you
use {\bf Integers}. The total number of integer values is $256^2 =
32768$. One possible value is, of course, zero. So the number of
negative and positive values differ by one. The choice is to favor
negative numbers, so Integers cover the range $-32768 \rightarrow
32767$. You generate an array using {\bf indgen}. What happens with
wraparound? What if {\bf x=5}, {\bf y=30000} and {\bf z=x*y}? Check it
out!
\subsection{4 bytes: Long Integers and Unsigned Long Integers}
The discussion here is exactly like that for 2-byte integers,
except that $256^2$ becomes $256^4$. What are the limits on these
numbers? See IDL help under ``Data Types'' and ``Integer Constants'' for
more information. You generate arrays using {\bf ulindgen} and {\bf
lindgen}.
\subsection{8 bytes: 64-bit Long Integers and Unsigned 64-bit Long
Integers}
The discussion here is exactly like that for 2-byte integers,
except that $256^2$ becomes $256^8$. What are the limits on these
numbers? See IDL help under ``Data Types'' and ``Integer Constants'' for
more information. You generate arrays using {\bf ul64indgen} and {\bf
l64indgen}.
\section {FLOATING DATATYPES IN IDL}
The problem with integer datatypes is that you can't represent
anything other than integral numbers---no fractions! Moreover, if you
divide two integer numbers and the result should fractional, but it
won't be; instead, it will be rounded down (e.g. $5 \over 3$ is
calculated as 1). To get around this, the {\it floating} datatype uses
some of the bits to store an {\it exponent}, which may be positive or
negative. You throw away some of the precision of the integer
representation in favor of being able to represent a much wider range of
numbers.
\subsection{4 bytes: Floats}
``Floating point'' means floating decimal point---it can wash all
around. With Floats, the exponent can range from about $-38 \rightarrow
+38$ and there is about 6 digits of precision. You generate an array
using {\bf findgen} and a single variable by including a
decimal point ({\bf x=3.}) or using exponential notation ({\bf x=3e5}).
\subsection{8 bytes: Double-Precision}
Like Float, but the exponent can range from about $-307
\rightarrow +307$ and there is about 16 digits of precision. You
generate an array using {\bf dindgen} and a single
variable by writing {\bf x=3d} or {\bf x=3d5}.
\section {STRINGS}
Strings store characters---letters, symbols, and numbers (but
numbers as {\it characters}---you can't calculate with strings! A string
constant such as {\bf hello} consists of five letters. It takes 5 bytes
to store this constant---one byte for each character. There are 256
possible characters for each of the bytes; with 2*26 letters (smalls and
caps) and 10 digits, this leaves 104 other possibilities, which are used
for things like semicolons and periods. You can generate an array of
strings with {\bf strarr} and a single string with {\bf x = 'Hi
there!!!'}.
\enddocument
\end