Bits Bytes and Number Systems- Binary, Denary, Hexadecimal, Octal and ASCII Codes tutorial |
||
Programming Tutorial |
Updated 22 Feb 2004 | |
| Tutorials: HTML and Web Design | C programming | Smalltalk Programming | ||
Contents
|
IntroductionThis tutorial is going to assist you with the different numbering systems that are used in programming. Programmers will need to be familiar with most of them. You are already familiar with our every day denary numbering system based on the unit 10. Computers only understand the binary number system based on the unit 2 denary. Programming often uses the hexadecimal system base on a unit of 16 denary. For example HTML uses hexadecimal numbering in the color attribute, e.g. color="FF00FF". Another less common system is octal based on 8 denary. You should know how to convert between the different systems. The ASCII table at the foot of this page is useful for a quick conversions up to 127 denary. The windows calculator (in scientific mode) can be used for conversions. College and University students may find that calculators are not allowed in the exam, OU course T223 is an example of this, therefore manual conversion calculations must be made. This should be practiced to speed up the process, the calculator only used to check your manual conversion. BitA binary digit is called a bit. Usually expressed as 0 and 1 the
two numbers of the binary numbering system. Reading a series of bits is very difficult and to make this process easier they are
often displayed in groups of 4 bits This grouping is quite interesting in that a group of 4 bits can be replaced by a single
hexadecimal digit
ByteA group of 8 bits are in a byte. With 8 bits ( binary digits ), there
exists 256 possible denary combinations. KilobyteThe value of a kilobyte is 1024. Worked out as 2^10. Normally Kilo refers to 1000 but in computing kilobyte is 1024. MegabyteLikewise, 1024Kb is referred to as a "Megabyte". Normally a Mega refers to a million. In computing 1 Mega byte is 1,048,576 bytes. Worked out as 2^20, or 1024*1024. 1 byte of memory can normally hold one of the following:
See the ASCII codes at the foot of this page which shows how the first 127 characters of 256 characters are used In every day life we Usually use the denary number system which has a base of
10. Number SystemsThe every day number system we use is the denary system, sometimes called the decimal system. In programming three number systems are commonly used, binary, hexadecimal and to a lesser extent octal .
How do numbering systems workTo understand this we will examine the Denary system in more detail. Because you are so used to the denary system and because it is very easy to multiply by 10, 100, or a 1000 etc you calculate the number in your head. Lets use the number 256 as an example. The calculation that is automatically done is the following The most important calculation to do is to work out the positional values for that system. The positional value is based on the powers of the number systems base value
Write down the Positional values for the number system you are using so for Denary we would write
Underneath the correct positional value write in your number
The calculation that is done
Add the 3 results 200 + 50 + 6
You can convert a number in any number system to a denary number using this calculation. Ensure you use the positional values for the number system you are using
Denary Numbering (base 10) sometimes called Decimal systemThe decimal system name should not be used because of confusion that this could be thought as introducing the decimal point and money systems Uses numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, that's 10 numbers. Hence base
10. Radix is another name for base 10.
A byte of memory can store a number in the range 0 to 255 Denary. Binary Numbering (base 2)A series of eight bits strung together makes a byte, much as 12 makes a dozen. With
8 bits, or 8 binary digits, there exist 2^8=256 possible combinations Binary numbering is the number system that is used by computers. Note: The positional value doubles as you go to the next positional on the left
A binary digit is called a bit. There are two possible states in a bit, Usually expressed as 0 and 1, the two numbers used in the binary number system. But the bit could represent on / off of an electrical circuit, yes / no, true / false,
-1 / 0, -1 / +1, zero / non zero, or similar 2 state binary wording. A byte of memory can store a number in the range 00000000 to 11111111 binary. How to Convert Binary to DenaryConvert 1011 binary to denary
Add the 3 results 8 + 0 + 2 + 1
Therefore 1011(One Zero One One) binary = 11 (Eleven) Denary Hexadecimal Numbering (base 16)Uses numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, that's 16 numbers. Hence base 16..A=10 Dec, B=11 DEC, C=12 DEC, D=13 DEC, E=14 DEC, F=15 Dec. By using the letters A-F a single digit only requires a single position (column).
A byte of memory can store a number in the range 00 to FF Hex Hexadecimal numbers are often displayed in groups of 2, to make them easier to read. E.g. 10 AF 3C 9F A single hexadecimal number requires 4 units of binary numbers. This makes it reasonably easy to convert between these two numbering systems. E.g. 1 = 0001 9 = 0101 A = 1010
Octal (base 8)Uses numbers 0, 1, 2, 3, 4, 5, 6, 7, , that's 8 numbers. Hence base 8.. A byte of memory can store a number in the range 0 to 377 Oct.
Binary SystemsThe Binary system
These states are usually represented by either the number 0 or 1 of the binary number system. |