Computer Numbering System
When dealing with computers at a very low level absolutely everything is either a 1 or a 0 (zero). This is called the binary numbering system. This system works very much the same as the decimal numbering system (What people use normally in our every day lives). The difference is that with the decimal system we have 10 different symbols to make up our numbers, namely 0,1,2,3,4,5,6,7,8,9. In binary we only have two symbols 0 and 1. In both systems we also use a positional system named The Order of Magnitude. So in Decimal we know that 10 is one order of magnitude larger then 1, and this also means that 10 is ten times larger then 1 because there are ten symbols to represent numbers. In binary 10 is also one order of magnitude larger then 1, but since there are only two symbols 10 is only twice as large as 1. With that in mind we can figure out that 10 in binary is equal to only two in decimal, but 10 in decimal is equal to 1010 in binary. If we apply a bit of reasoning we can see how these numbers are related. In decimal, each position to the left is one order of magnitude greater then the one to the right. And we know that one order of magnitude is ten times larger then the last in the decimal system, meaning that each order of magnitude can be calculated as 10n, where n is the position of the symbol from the right most symbol. In the binary system it is the same except that instead of using 10 in the formula we use 2n. This means that the symbols in the number 1010 equal the following:
- 1 * 8 = 8
- 0 * 4 = 0
- 1 * 2 = 2
- 0 * 1 = 0
Which equals 10 in decimal. Another note when using different numbering systems, we normally put the base number in subscript beside the number so that we know which system we are referring to. So 4510 would be the number 45 in the decimal system and the number 01012 would be the number 5 in binary. Another note is that in the binary system we will pad zeros in front of the number to make the total length a multiple of four. This is done because a length of four in binary is equal to half a byte in computer terms and helps humans understand the correlation between the two, since they are highly abstract concepts as you will see soon.
Data Lengths
A data length is the measurement of certain units within a computer and are similar to how we use the terms Million, Billion and Trillion. Data lengths are not constant, they will very from processor, but I will be largely referring to the normal 8086 architecture normally in use today.
First we have a single bit, a bit is the smallest representable number in a computer, it can either be 1 or 0. The next size up is a byte, a byte is made up of exactly eight bits (called an octet), it is extremely important because this is the building block of all other data lengths. A word is defined as four bytes or 32 bits. Then we have a double word which is eight bytes or 64 bits. Lastly, we have a quad word or quadruple word, which is defined as sixteen bytes or 128 bits. It is important to know these because they are the building blocks of our modern day computer architecture, especially since we are migrating from 32 bit processors to 64 bit processors now.
Data Types
Data types are a completely abstract thing, meaning that it is something that is made up by programmers to help in understanding how a microprocessor works. In reality a microprocessor does not take a data type into consideration. For instance, if a programmer defines a character variable as "A" and an integer variable as 65. They are two completely different and distinct things but a microprocessor simply sees 010000012 and does not care or know which data type is defined.
*Note: 65 does not always represent "A", this will become apparent when we discuss character sets later.
So why bother with data types? Well, they make code both easier to read and helps trap errors and other security risks. Most of the time data types are strictly enforced by the language meaning that even though 65 and "A" are technically the same, they cannot be used interchangeably. But in some languages the data types are not enforced and can be freely converted. And in other languages datatype conversion is limited, where we can freely convert the number 1 to the character "1" but we cannot convert a letter such as "A" to the number 65. Data types also have data lengths, but the lengths are highly dependent on both the language and processor in use. So for simplicity I will name the most common size for a 32 bit processor but they may not be correct for all languages or processors.
Boolean (bool)
16 bits
A boolean is used to represent either true or false and normally, only has two possible values 0 and 1. The reason they are defined to be so large though is strictly for performance reasons. It is easier for a computer to read and transfer 16 bits then a single bit.
Integer (int)
16 bits
Can only represent numbers, trying to assign a character will result in an error. The normal range of representable numbers is 0 to 65, 535 or -32,768 to 32,767 if the numbers are signed.
Long Integer (long)
64 bits
A long is simply an integer with more room. The range for a long is 0 to 4,294,967,295 or if it is signed -2,147,483,648 to 2,147,483,647.
Short Integer (short)
8 bits
A short is simply an integer with less room. The range is 0 to 255 or -128 to 127 if signed.
Single Precision Floating Point Number (float)
32 bits
A float is used to represent real numbers, or numbers with a decimal place. Normally these numbers are represented by a formula known as IEEE-754. This allows for very large and very small numbers to be represented.. The exact range is dependent on the implementation however.
Double Precision Floating Point Number (double)
64 bits
A double is implemented in the same way that a float is, the only difference is the bits allocated to it, allowing for a much greater range in numbers.
Character (char)
8 bits
Represents a single character or symbol in a written language. 8 bits is the most common size of a char and is only really used for ASCII representation. We will discuss more of this in a later article.
This work is licensed under a Creative Commons License.
Privacy Policy