A single byte can store an integer that takes on a value from 0 to 255. The interpretation of the bits in the byte uses normal binary representations for numbers. You might not see this representation often.Floating Point Numbersunsigned char x;
A single byte can also store an integer that takes on a value from -128 to +127. In this case, one bit in the byte is used as a sign bit. In C, an integer of this type is declared using:char x;Larger integers can be stored using two bytes. Two bytes can store 216 - 1 or 65536 numbers from 0 to 65535. The numbers represented can run from 0 to 65535. In C, an integer of this type is declared using:
or
short int x;unsigned int x;Signed integers take two bytes and use one bit to store the sign (plus or minus), and have a range from -32768 to +32767, and are declared like this:int x;NOTE: In some cases, the declaration above will give you an integer that takes four bytes, and which can have much larger values.Finally, there is a long integer that is used for large integers. A long integer takes four bytes, and will handle integers from -2,147,483,648 to -2,147,483,647. The form of the declaration is:
long int x;Now, none of these representations will handle something like 2.59 - a number that is not an integer. You need to use a floating point representation for those numbers.
Data Type Number of Bytes Number of Bits Float 4 32 Double 8 64 Long Double 12 96 float 4 32
double 8 64
long double 12 96
IEEE has written a standard for floating point numbers. The simplest IEEE representation uses a 32 bit word (four bytes) and looks something like this:
S E E E E E E E E S F F - - F F F F F F F F F F 0 1 8 9 31
float x;
If you want a more precise representation of a number, you can use a double precision floating point representation that uses eight (8) bytes. The declaration is:
double x;
Numerous instruments transmit measurement data using ASCII coded numbers. In an ASCII coded number. For example, a measurement that yields a value 3.145 would be transmitted to a computer with the following sequence of characters.
This approach can be used to put data into a file for data storage. Most data files use this representation. For details on the ASCII code, click here.
- An ASCII character 3,
- An ASCII character ., (That's a period!)
- An ASCII character 1,
- An ASCII character 4,
- An ASCII character 5,
- A separator that could be either one of these:
- If the next piece of data is stored in another column, then the next character in the file should be an ASCII character Tab, (A tab character) That would produce a "Tab-delimited" file since the delimiter is a tab character.
- There are times when "Comma-delimited" files are used. In that situation, the tab character is replaced by a comma.
- If the next piece of data starts another row, then it is often the case that two characters are used. Those characters are an ASCII character CR, (Carriage return) and an ASCII character LF, (Line Feed). (In manual typewriter days, the carriage return took the carriage back to the first position at the left of the page, and the line feed advanced to the next line.)