Thursday, February 5, 2009

octal number system

A numbering system that uses eight digits. It is used as a shorthand method for representing binary characters that use six-bits. Each three bits (half a character) is converted into a single octal digit. Okta is Greek for 8.


Decimal Binary Octal
0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7. Numerals can be made from binary numerals by grouping consecutive digits into groups of three (starting from the right). For example, the binary representation for decimal 74 is 1001010, which groups into 001 001 010 — so the octal representation is 112.

In decimal systems each decimal place is a base of 10. For example:


In octal numerals each place is a power with base 8. For example:


By performing the calculation above in the familiar decimal system we see why 112 in octal is equal to 64+8+2 = 74 in decimal.

Octal is sometimes used in computing instead of hexadecimal.

binary number system

A method of representing numbers in which only the digits 0 and 1 are used. Successive units are powers of 2. Also called binary system.

binary system, numeration system based on powers of 2, in contrast to the familiar decimal system, which is based on powers of 10. In the binary system, only the digits 0 and 1 are used. Thus, the first ten numbers in binary notation, corresponding to the numbers 0,1,2,3,4,5,6,7,8, and 9 in decimal notation, are 0,1,10,11,100,101,110,111,1000, and 1001. Since each position indicates a specific power of 2, just as the number 342 means (3 × 102) + (4 × 101) + (2 × 100), the decimal equivalent of a binary number can be calculated by adding together each digit multiplied by its power of 2; for example, the binary number 1011010 corresponds to (1 × 26) + (0 × 25) + (1 × 24) + (1 × 23) + (0 × 22) + (1 × 21) + (0 × 20) = 64 + 0 + 16 + 8 + 0 + 2 + 0 = 90 in the decimal system. Binary numbers are sometimes written with a subscript “b” to distinguish them from decimal numbers having the same digits. As with the decimal system, fractions can be represented by digits to the right of the binary point (analogous to the decimal point). A binary number is generally much longer than the decimal equivalent; e.g., the number above, 1011010b, contains seven digits while its decimal counterpart, 90, contains only two. This is a disadvantage for most ordinary applications but is offset by the greater simplicity of the binary system in computer applications. Since only two digits are used, any binary digit, or bit, can be transmitted and recorded electronically simply by the presence or absence of an electrical pulse or current. The great speed of such devices more than compensates for the fact that a given number may contain a large number of digits.

decimal system

A number system based on units of 10.
A system of measurement in which all derived units are multiples of 10 of the fundamental units

decimal system [Lat.,=of tenths], numeration system based on powers of 10. A number is written as a row of digits, with each position in the row corresponding to a certain power of 10. A decimal point in the row divides it into those powers of 10 equal to or greater than 0 and those less than 0, i.e., negative powers of 10. Positions farther to the left of the decimal point correspond to increasing positive powers of 10 and those farther to the right to increasing negative powers, i.e., to division by higher positive powers of 10. For example, 4,309=(4×103)+(3x102)+(0×101)+(9×100)=4,000+300+0+9, and 4.309=(4×100)+(3×10−1)+(0×10−2)+(9×10−3)=4+3/10+0/100+9/1000. It is believed that the decimal system is based on 10 because humans have 10 fingers and so became used to counting by 10s early in the course of civilization. The decimal system was introduced into Europe c.1300. It greatly simplified arithmetic and was a much-needed improvement over the Roman numerals, which did not use a positional system. A number written in the decimal system is called a decimal, although sometimes this term is used to refer only to a proper fraction written in this system and not to a mixed number. Decimals are added and subtracted in the same way as are integers (whole numbers) except that when these operations are written in columnar form the decimal points in the column entries and in the answer must all be placed one under another. In multiplying two decimals the operation is the same as for integers except that the number of decimal places in the product, i.e., digits to the right of the decimal point, is equal to the sum of the decimal places in the factors; e.g., the factor 7.24 to two decimal places and the factor 6.3 to one decimal place have the product 45.612 to three decimal places. In division, e.g., 4.32|12.8 where there is a decimal point in the divisor (4.32), the point is shifted to the extreme right (i.e., to 432.) and the decimal point in the dividend (12.8) is shifted the same number of places to the right (to 1280), with one or more zeros added before the decimal to make this possible. The decimal point in the quotient is then placed above that in the dividend, i.e., 432|1280.0 zeros are added to the right of the decimal point in the dividend as needed, and the division proceeds the same as for integers. The decimal system is widely used in various systems employing numbers. The metric system of weights and measures, used in most of the world, is based on the decimal system, as are most systems of national currency.

Practical Guide to Binary, Decimal and Hexadecimal Numbers

DISCLAIMER: This guide on numbers was written to support a series of other documents about various Internet protocols. It is not meant to be the ultimate complete source of everything there is to know; all I want to do is refresh or introduce the concepts used in other documents.

The Decimal System.
You are undoubtedly familiar with the decimal numbering system, which is why we will start with it. After all, starting with something you already know will make it easy o introduce the concepts we will use in the other numbering systems.

The Decimal system is what you use everyday when you count/ Its name is derived from the Latin word Decem, which means ten. This makes sense since the system uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. These digits are what we call the symbols of the decimal system.

Since we have ten symbols, we can count from 0 to 9. Note that 0, even though it often means 'nothing', is a symbol that counts! After all, you need a numeric way to say 'nothing'. When you want to count past what your simple symbols will allow, you combine multiple digits. The table below shows this concept, which is demonstrated by adding one for every step:

0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29

The table has 10 numbers across, which is the same number of symbols as the decimal system. As you look at row 2, you notice that we added symbol 1 to the 0, making 10. In row 3, the one is replaced by a 2, giving 20. The further you go down the table, the higher the numbers get. You could say that the first row of the table really has a leading 0, after all the 'value' of 01 is the same as the value of one. All 2-digit decimal numbers can be put in a somewhat larger table much like the one above, which looks like this:

Least Significant Digit

0 1 2 3 4 5 6 7 8 9
Most
Significant

Digit
0 00 01 02 03 04 05 06 07 08 09
1 10 11 12 13 14 15 16 17 18 19
2 20 21 22 23 24 25 26 27 28 29
3 30 31 32 33 34 35 36 37 38 39
4 40 41 42 43 44 45 46 47 48 49
5 50 51 52 53 54 55 56 57 58 59
6 60 61 62 63 64 65 66 67 68 69
7 70 71 72 73 74 75 76 77 78 79
8 80 81 82 83 84 85 86 87 88 89
9 90 91 92 93 94 95 96 97 98 99

This shows the concept of the Least Significant Digit or the LSD, which is the digit on the right. As you can see, it the digit that increases every time we increase the number. When we run out of LSD's, we increase the digit to the left of it. In this example, it is the Most Significant Digit or the MSD. When we run out of MSD's, we add another digit to the left, again by increasing the imaginary 0 there.

For example, after 98, we increase the LSD to get 99, which is the same as 099. When we add one, the LSD rolls to 0, so we increase the next digit over to the left (The current MSD), which now becomes 0, which means we roll the next digit over (The 0), which gives us 100. Note that the MSD is now the 1.

As a general rule, the significance of the digits becomes greater as we move to the left, towards the MSD. This is why when we count the digits in a number, we always count them from the Right hand side (LSD) to the Left Hand Side (MSD). In the decimal number 346981, we say that 1, the LSD, is digit number 0. The 9 is digit number 2, and the three is digit number 5. No matter what system, decimal, binary or hexadecimal, we always count digits from right to left, LSD will always be on the right, and we will always express the digit number in decimal.

Just like we assume in normal life that things are done in Decimal, we will do everything in Decimal as well. All the math that is to follow is performed in decimal, unless specifically otherwise mentioned. Since decimal is the normal numeric system, there is no special notation used to identify decimal numbers.

Although it is valid to think of decimal numbers as having a large number of 0's to the left of the MSD, and we will at times write these 0's down, you must be careful when entering numbers in a computer. Some programs will interpret a leading zero in front of a number to mean "This is not decimal". You have been warned! Also, as we all know, negative numbers exist in real life. In our explanation, we do not need them, and therefor we are hereby setting the rule that negative numbers will not be used; we will only use the number 0 and up. To make matters even simpler, we will only allow whole numbers. Even though there are fractions and decimal numbers in real life, we also do not need them. So what we are left with are all whole numbers 0 and up. Mathematicians call these Natural Numbers; computer scientists call them unsigned integers. Remembering that you should only see Natural Numbers (whole numbers 0 and up) can help you find mistakes.

Decimal Math
Now that we have looked at the Decimal Number System, let's take a quick look at traditional, decimal math. The six operations we are concerned with are addition, subtraction, multiplication, integer division, modulo and exponents. We will discuss each shortly:

Addition: The process of adding two numbers. This is done by simply increasing one number with the other: 2+3=5, because if you count three steps up from the digit two you get to the digit five. 7+5=12, because when when you count five steps up from seven you get 12.

Subtraction: The process of subtracting one number from another. This is done by simply decreasing one number by the number of steps indicated by another: 5-3=2, because if you count three steps down from 5 you get two. 12-5=7 because when you count five steps down from twelve, you get to 7.

So, Subtraction is in essence the exact reverse operation of addition. The only thing that is different is the direction in which the counting happens.

Multiplication: The result of the process of repeatedly adding numbers. This is done by repeated addition of a number to itself: 2*3=6 because 2+2+2=6. 8*6=48 because 8+8+8+8+8+8=48. Obviously, 5*0=0, because if you add no fives, you get nothing, and 5*1=5, because one five is simply 5.

Integer Division: The inverse process of Multiplication. In principle, this is done by repeated subtraction of a number from another number: 6/2=3, because 6-2-2-2=0, you subtract two three times to get to 0, 48/8=6 because 48-8-8-8-8-8-8=0. Note that division does not always 'work' this way: 20/8 does not fit the mold, because 20-8-8=4, and therefore we would need a 'part of 8'. We are only interested in whole number, so in cases like this we will say that 20/8 = 2, with a remainder of 4. This remainder is what is called the Modulo. Obviously, division by 20/1=20 because you only need one 20 to make 20, and the modulo will always be 0. Division by 0 is not possible; after all no matter how often zero is subtracted, the number will never decline. Note that this is a special case where Integer Division is not the reverse of multiplication. Note that Division By Zero Is Impossible And Has No Answer, impossible means the answer is not 0 or infinitely large, as is often wrongly thought. Since you have to divide to calculate the modulo, anything modulo 0 is also an invalid operation. Note especially that 0 may be divided by anything; 0/anything is always zero. The modulo will always be zero as well.

Notice that the processes of Multiplication is no more than a mathematical shorthand for the repetition of the process of Addition.

Exponents: The result of the process of repeated multiplication of a number by itself. 2^3=8 because 2*2*2=8 because 2*(2+2)=8 because (2+2)+(2+2)=8. 3^4=81 because 3*3*3*3=81 because 3*3*(3+3+3)=81 because 3*((3+3+3)+(3+3+3)+(3+3+3))=81 because ((3+3+3)+(3+3+3)+(3+3+3))+((3+3+3)+(3+3+3)+(3+3+3))+((3+3+3)+(3+3+3)+(3+3+3))=81. A special case is the exponent 0. By definition, any number^0=1. This is an exception to the rules listed previously, the reason why this is important will become clear later on.

Just like Multiplication is Math Shorthand for the result of repeated Addition of a number to itself, Exponents are shorthand for the result of repeated Multiplication of a number by itself.

Here again are the symbols we will use to represent these mathematical operations:

Operation Symbol
Addition +
Subtraction -
Multiplication *
Division /
Modulo %
Exponent ^

Note that these symbols are considered 'standard', they are what many modern programming languages (Such as C++ and Java) and Application Software (Such as Spreadsheets) use. When some of these operators are combined with numbers, we get an expression. Expressions are evaluated in a certain order; all of the exponents are computed first, followed by the multiplications, divisions and modulos, followed by the additions and subtractions. 4+2*3=10 because 2*3=6 and 4+6=10. Also, 4+3*2^2=16 because 2^2=4 and 3*4=12 and 4+12=16. 2^2*3+4=16 as well, for the same reason.

If on the other hand you wanted to first add 4 and three, then multiply that by 2, and then calculate the square, you have to explicitly describe that process by using parenthesis. Anything inside parenthesis is looked upon as a separate expression, which is evaluated first. For our example, you would have to write: ((4+3)*2)^2, which will be evaluated as 4+3=7 and 7*2=14 and 14^2=196.

There are numerous other Math operations, and some of the ones discussed here would not be so simple to explain had we not set the rule that we will only use Unsigned Integers / Natural Numbers. Whatever you do, keep in mind that this is not the complete guide to everything there is to know about math.

A Mathematical look at Decimal Numbers.
Now that we have some math in our hands, let's look at Decimal numbers again. Take the number 7 for example. What can we say about it? It has only one digit (7), which is both the Most Significant Digit and the Least Significant Digit. The digit is in Position 0. The value it expresses is 7, and it is a decimal number.

A mathematical way of describing 7 would be to say that it represents the number of ones in the decimal world. 7 simply means seven ones, or 7*1.

Looking at the number 36, we can do the same thing: It has 2 digits (3 and 6), 3 is the most significant digit, 6 is the least significant digit. The LSD is in position 0, the MSD is in position 1. The value it represents is 36, and it is a decimal number.

A mathematical way of describing 36 would be to say that it it represents three tens, and six ones in the decimal world, or 3*10 + 6*1. Three teens and six ones make thirty-six.

1369 works the same: 4 digits, 1 is MSD, 9 is LSD, MSD in position 3, LSD in position 0, value is 1369 in Decimal. Or, mathematically: one thousand, three hundreds, 6 tens and 9 ones in the decimal world, or 1*1000 + 3*100 + 6*10 + 9*1.

If you take a look at the values (1000, 100, 10, 1) by which we multiply the digits (1, 3, 6, 9) and the relationship to the digit positions (3, 2, 1, 0), and combine this with the knowledge that this the decimal number set, you could come up with the following math to describe the above number in a different way: 1*10^3 + 3*10^2 + 6*10^1 + 9*10^0.

Similarly, 36 can be described as 3*10^1 + 6*10^0, and 7 as 7*10^0. Before you move on, it is important that you understand the math here; without it you will get lost when we die in to the hexadecimal and binary number set.

Hexadecimal Numbers.
In principal, Hexadecimal numbers work in the exact same way as decimal numbers do. Nearly all the same rules apply. The main difference is that there are more symbols. In the case of Hexadecem, Latin for 16, there are 16. The first ten are old faithful 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The six new ones are A, B, C, D, E, F. Just like we made a little counting table for Decimal, we can make one for Hexadecimal as well:

0 1 2 3 4 5 6 7 8 9 A B C D E F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F

Apart from the difference in the symbols and the different number of them, the Math rules in Hexadecimal, which we will from now on simply call Hex, are the same as the rules in Decimal.In Hexadecimal math, 4+1=5 and 6+3=9 and 9+3=C. As in Decimal math, you add an MSD to the left in Hex when you run out of Symbols, example in Hex: C+5=11 and Hex 11+3C=4D. Although this sounds simple and logical, our brain has trouble with it since we are trained in decimal! A calculator can be handy in cases like this.

The rule for Decimal numbers holds true for Hex numbers for a far as the mathematical representation of the digits that make up a number. In Hex math, the following is true:

D1C5 = D*10^3 + 1*10^2 + C*10^1 + 5*10^0

The complete table for all 2-digit Hex numbers is obviously larger then the one for Decimal, since we have more symbols, there are more possible combinations. Given 10 symbols in Decimal, that table had 100 elements (10 rows by 10 columns). The hex table will thus have 256 elements (16 rows by 16 columns):

Least Significant Digit
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0 1 2 3 4 5 6 7 8 9 A B C D E F
1 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
2 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
3 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
4 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
5 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F
6 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F
7 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F
8 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
9 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F
A A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF
B B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF
C C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
D D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
E E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF
F F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF

From now on, we will identify hexadecimal numbers in either of two ways: By putting an H behind them (Such as 12H) or by putting 0x in front (Such as 0x12, standard C++ notation). The Decimal Math Functions work the same on Hexadecimal Numbers. Because the symbol set is different and larger, you will however get different results most of the time. For example: 10+10=20 and 10H+10H=20H, but 50+50=100 and 50H+50H=A0H!

Binary Numbers
As with Hexadecimal numbers, Binary numbers are just a different set of symbols, but all the same math applies. Bi is Latin for two; the binary number set only has two symbols, 0 and 1. The counting table for Binary is very simple indeed:

0 1
10 11
100 101

As you probably had expected, the Math works the same, although the numbers get really big due to the limited symbol set. In Binary math: 1+1=10 and 110+101=1011. The Mathematical Representations are also still the same. Again in Binary:

10 = 1*10^1+0*10^0

We will append a B to the end of Binary numbers from now on, as in 1011B and 100B. All standard Math functions work in Binary. Binary Digits are sometimes called Bits. Numbers consisting of four bits are known as nibbles, and numbers of 8 bits are known as bytes.

Binary and Decimal and Hex numbers.
So why do we need all of this? A computer is a Binary machine deep inside. It knows only ones and zeroes. It uses the Binary System to do everything it does. When your computer shows you Decimal numbers, they are merely a translation of the Binary representation of those numbers inside the machine. Bits and Bytes in Binary form are obviously long and cumbersome, you would not want to work with them on a daily basis.

Since the Byte is the unit of information that our computers work with (A group of 8 bits), it was convenient to find a way to express bytes that was still sort of meaningful to Humans, and easy to work with for a computer. This is where hexadecimal came in to play: One Hex digit can be expressed in four Bits, 8 bits, or two nibbles, or one byte can thus be expressed by two hex digits. The table below will let you convert values easily between the various numbering systems:

Binary Hex Decimal
0 0 0
1 1 1
10 2 2
11 3 3
100 4 4
101 5 5
110 6 6
111 7 7
1000 8 8
1001 9 9
1010 A 10
1011 B 11
1100 C 12
1101 D 13
1110 E 14
1111 F 15

As said before, a Byte, the natural unit of information for a computer, is 8 bits wide. Therefore, the largest number a computer can easily handle will be 11111111B. It is fairly easy to convert this number to a Decimal number, after all we know it means in Binary:

11111111=1*10^111+1*10^110+1*10^101+1*10^100+1*10^11+1*10^10+1^10^1+1*10^0

All we have to do to convert the numbers in the right-hand side mathematical expression to Decimal, according to the table listed above:

1*2^7+1*2^6+1*2^5+1*2^4+1*2^3+1*2^2+1*2^1+1*2^0=
128+64+32+16+8+4+2+1=255

That is one of the magic numbers you are probably familiar with: 255 is the largest Decimal number a computer can store in one byte. The same holds true for Hexa-decimal:

1*2^7+1*2^6+1*2^5+1*2^4+1*2^3+1*2^2+1*2^1+1*2^0=
80+40+20+10+8+4+2+1=FF

With the little table above, it would have been simple to just split the byte in two nibbles, and then to look up the Hex digit for each nibble; 1111B = FH, so 1111 1111B = FFH. You will find that little table works the other way around too: E7H = 1110 0111B because EH = 1110B and 7H = 0111B. For conversions to and from Decimal, you still have to do the Math though. Or, you can reference the more complete table below.

What you should know now...
You should now be able to look at numbers in either one of the three systems, Hexadecimal, Binary or Decimal, and understand how to convert them to each other. The easiest way to do so is use of the table above. This will matter later when the details of the IP networking protocol are discussed in great detail. If you do not get the Math yet, read this again in a day or two. Once you grasp the concept, it is not hard. Although most of the math will actually be done in the examples, you will gain better understanding if you do not just assume what is said, but actually understand what is happening and why.

Numbering systems tutorial

What is it?

There are many ways to represent the same numeric value. Long ago, humans used sticks to count, and later learned how to draw pictures of sticks in the ground and eventually on paper. So, the number 5 was first represented as: | | | | | (for five sticks).

Later on, the Romans began using different symbols for multiple numbers of sticks: | | | still meant three sticks, but a V now meant five sticks, and an X was used to represent ten of them!

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.


--------------------------------------------------------------------------------

Decimal System

Most people today use decimal representation to count. In the decimal system there are 10 digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

These digits can represent any value, for example:
754.
The value is formed by the sum of each digit, multiplied by the base (in this case it is 10 because there are 10 digits in decimal system) in power of digit position (counting from zero):



Position of each digit is very important! for example if you place "7" to the end:
547
it will be another value:



Important note: any number in power of zero is 1, even zero in power of zero is 1:



--------------------------------------------------------------------------------

Binary System

Computers are not as smart as humans are (or not yet), it's easy to make an electronic machine with two states: on and off, or 1 and 0.
Computers use binary system, binary system uses 2 digits:

0, 1

And thus the base is 2.

Each digit in a binary number is called a BIT, 4 bits form a NIBBLE, 8 bits form a BYTE, two bytes form a WORD, two words form a DOUBLE WORD (rarely used):



There is a convention to add "b" in the end of a binary number, this way we can determine that 101b is a binary number with decimal value of 5.

The binary number 10100101b equals to decimal value of 165:




--------------------------------------------------------------------------------

Hexadecimal System

Hexadecimal System uses 16 digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

And thus the base is 16.

Hexadecimal numbers are compact and easy to read.
It is very easy to convert numbers from binary system to hexadecimal system and vice-versa, every nibble (4 bits) can be converted to a hexadecimal digit using this table:

Decimal
(base 10) Binary
(base 2) Hexadecimal
(base 16)
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F



There is a convention to add "h" in the end of a hexadecimal number, this way we can determine that 5Fh is a hexadecimal number with decimal value of 95.
We also add "0" (zero) in the beginning of hexadecimal numbers that begin with a letter (A..F), for example 0E120h.

The hexadecimal number 1234h is equal to decimal value of 4660:




--------------------------------------------------------------------------------

Converting from Decimal System to Any Other

In order to convert from decimal system, to any other system, it is required to divide the decimal value by the base of the desired system, each time you should remember the result and keep the remainder, the divide process continues until the result is zero.

The remainders are then used to represent a value in that system.

Let's convert the value of 39 (base 10) to Hexadecimal System (base 16):



As you see we got this hexadecimal number: 27h.
All remainders were below 10 in the above example, so we do not use any letters.

Here is another more complex example:
let's convert decimal number 43868 to hexadecimal form:



The result is 0AB5Ch, we are using the above table to convert remainders over 9 to corresponding letters.

Using the same principle we can convert to binary form (using 2 as the divider), or convert to hexadecimal number, and then convert it to binary number using the above table:



As you see we got this binary number: 1010101101011100b


--------------------------------------------------------------------------------

Signed Numbers

There is no way to say for sure whether the hexadecimal byte 0FFh is positive or negative, it can represent both decimal value "255" and "- 1".

8 bits can be used to create 256 combinations (including zero), so we simply presume that first 128 combinations (0..127) will represent positive numbers and next 128 combinations (128..256) will represent negative numbers.

In order to get "- 5", we should subtract 5 from the number of combinations (256), so it we'll get: 256 - 5 = 251.

Using this complex way to represent negative numbers has some meaning, in math when you add "- 5" to "5" you should get zero.
This is what happens when processor adds two bytes 5 and 251, the result gets over 255, because of the overflow processor gets zero!



When combinations 128..256 are used the high bit is always 1, so this maybe used to determine the sign of a number.

The same principle is used for words (16 bit values), 16 bits create 65536 combinations, first 32768 combinations (0..32767) are used to represent positive numbers, and next 32768 combinations (32767..65535) represent negative numbers.


--------------------------------------------------------------------------------

There are some handy tools in emu8086 to convert numbers, and make calculations of any numerical expressions, all you need is a click on Math menu:



Base converter allows you to convert numbers from any system and to any system. Just type a value in any text-box, and the value will be automatically converted to all other systems. You can work both with 8 bit and 16 bit values.

Multi base calculator can be used to make calculations between numbers in different systems and convert numbers from one system to another. Type an expression and press enter, result will appear in chosen numbering system. You can work with values up to 32 bits. When Signed is checked evaluator assumes that all values (except decimal and double words) should be treated as signed. Double words are always treated as signed values, so 0FFFFFFFFh is converted to -1.
For example you want to calculate: 0FFFFh * 10h + 0FFFFh (maximum memory location that can be accessed by 8086 CPU). If you check Signed and Word you will get -17 (because it is evaluated as (-1) * 16 + (-1) . To make calculation with unsigned values uncheck Signed so that the evaluation will be 65535 * 16 + 65535 and you should get 1114095.
You can also use the base converter to convert non-decimal digits to signed decimal values, and do the calculation with decimal values (if it's easier for you).

These operation are supported:


~ not (inverts all bits).
* multiply.
/ divide.
% modulus.
+ sum.
- subtract (and unary -).
<< shift left.
>> shift right.
& bitwise AND.
^ bitwise XOR.
| bitwise OR.


Binary numbers must have "b" suffix, example:
00011011b

Hexadecimal numbers must have "h" suffix, and start with a zero
when first digit is a letter (A..F), example:
0ABCDh

Octal (base 8) numbers must have "o" suffix, example:
77o

Computer Number Systems

All computers do the amazing things that they do by simply manipulating ones and zeros. Computers can only do binary (base 2) arithmetic. You must be able to use the binary number system in order to appreciate how the computer works. Since the computer works with the binary number system and since it is relatively easy to convert hexadecimal (base 16) and octal numbers (base 8) into binary, computer scientists need to be familiar with the octal and hexadecimal number systems.
I. Numbering Systems
1. Decimal System
o base 10
o valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2. Binary System
o base 2
o valid digits - 0, 1
3. Octal System
o base 8
o valid digits - 0, 1, 2, 3, 4, 5, 6, 7
4. Hexadecimal System
o base 16
o valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
o A refers to decimal 10, B refers to decimal 11, etc.
II. To convert a number in a base other than 10 to base 10
1. Easy way: If you need to convert 345 (base 8) to decimal, you would label the three columns as the 1's, 8's, and 64's columns from right to left. Then, you would multiply the digits by these column labels and compute the sum of the 3 products. Since a 3 is in the 64's column, you multiply to obtain 192. Since 4 is in the 8's column, you multiply 4 x 8 to get 32. Then add 32 to the 192 from the step before to get a running total of 224. Finally, since a 5 is in the 1's column, multiply 1 x 5 to get the product of 5 and add it to the running toal of 224 to get 229. That final value, 229, is the decimal equivalent to the original number 345 (base 8).


2. Formal way: Expand the number 345 (base 8) into expanded form. Expanded form is written as

(3 x 82) + ( 4 x 81) + (5 x 80) = 229

III. To convert a decimal number into a base other than 10
1. Write out the powers in the other base starting at the power of 0 until you reach a number higher than the given number.
2. Divide the highest power of the base that can divided at least once into the given number.
3. Put the quotient of that division into a column that will eventually be the leftmost digit of the final answer.
4. Continue steps 2 & 3 using the remainder of the previous division but add each successive quotient to the right of previous quotients in the final answer.

Convert the following decimal (base 10) numbers to binary (base 2):

1. 32 =
2. 110 =

Convert the following decimal numbers to octal (base 8):

3. 21 =
4. 58 =

Convert the following decimal numbers to hexadecimal (base 16):

5. 1113 =
6. 1029 =

Convert the following binary numbers to decimals:

7. 11111110 =
8. 100111 =

Convert the following octal numbers to decimals:

9. 11 =
10. 266 =

Convert the following hexadecimal numbers to decimals:

11. A11=
12. 13 =

Add the following binary numbers. Set each problem up 'vertically' first.

13. 1000 + 11 =
14. 10101111 + 1011111 =

Add the following octal numbers. Set each problem up 'vertically' first.

15. 362 + 17 =
16. 177 + 17 =

Add the following hexadecimal numbers. Set each problem up 'vertically' first.

17. 288 + F2 =
18. EF0 + B9 =

Subtract the following binary numbers. Set each problem up 'vertically' first.

19. 1001 - 110 =
20. 110 - 11 =

Subtract the following octal numbers. Set each problem up 'vertically' first.

21. 23 - 7 =
22. 330 - 22 =

Subtract the following hexadecimal numbers. Set each problem up 'vertically' first.

23. B12 - 17 =
24. 98 - 12 =

Convert the following binary numbers directly to hexadecimal numbers.

25. 1011 1111 =

26. 1010 =
27. 11 0010 =
28. 110010101101 =

Convert the following hexadecimal numbers directly to binary numbers.

29. C3 =
30. F1F =

Followers