|
-
Mar 17th, 2012, 09:35 PM
#1
Thread Starter
Addicted Member
How To Transform (Convert) Numbers Between Decimal, Binary, Hex, and Octal
In order to determine how to transform numbers between decimal, binary, hex and octal (numbers in base 10, 2, 16 and 8) you must first learn how to count in other bases including binary. Counting in binary is almost identical to counting in decimal, the only difference is that the highest digit allowed is 1 instead of 9, meaning it only consists of the lowest digit 0 and the highest digit 1. The rest is the same, simply add one by adding one to the far right column.
Binary - Decimal
0000 = 0; to add one in binary just add 1 to the far right hand column just like decimals so 0000 + 0001 = 0001.
0001 = 1; as 1 is the highest digit allowed in base 2 you can't add 1 and make it 0002, instead it is exactly the same as getting to the highest digit in base 10 which is 9, meaning that in binary 0001 + 0001 = 0010.
0010 = 2, and so on.
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
Now that you can count in binary, observe that:
Binary - Decimal
0001 = 1 (1 x 2^0 = 1) Please note that any number to the power of 0 = 1 e.g. 8^0 = 1.
0010 = 2 (1 x 2^1 = 2) Please also note that any number to the power of 1 = number e.g. 8^1 = 8.
0100 = 4 (1 x 2^2 = 4)
1000 = 8 (1 x 2^3 = 8)
Which are all powers of 2, meaning each column represents a power of 2 in the same way that each column in decimal represents a power of 10.
This means that the decimal value of any binary number can be determined simply by adding the value of the bits that are set:
If the first bit is set ie 0001 then the decimal value is + 1*2^0 (+ 1)
If the second bit is set ie 0010 then the decimal value is + 1*2^1 (+ 2)
If the third bit is set ie 0100 then the decimal value is + 1*2^2 (+ 4)
If the 4th bit is set ie 1000 then the decimal value is + 1*2^3 (+ 8)
Note that any bits that are not set have the value of zero as 0 x 2^any number = 0 e.g. 0 x 2^3 -=0.
So to convert from binary to decimal is now easy, simply add the value of each bit:
1111(binary) = 1 x 2^0 + 1 x 2^1 + 1 x 2^2 + 1 x 2^3 = 1 + 2 + 4 + 8 = 15
What is the value of the binary number 0101 as a decimal?
0101(binary) = 1 x 2^0 + 0 x 2^1 + 1 x 2^2 + 0 x 2^3 = 1 + 0 + 4 + 0 = 5(decimal)
Now you tell me: what is the binary number 1010 as a decimal?
If you can answer, good job, you have learned how to count in binary and then convert from binary to decimal.
-------------------------------------------------------------------------------
Now you have made the breakthrough you can move on to count in hex. Hex is base 16. How do I count in base 16 when the digits used to represent base 10 numbers run out at 9 [0-9]?
The answer is that letters are used to represent numbers greater than 9. Specifically:
10 = A
11 = B
12 = C
13 = D
14 = E
15 = F
Which can be summarised as Hex: base 16 [0-9][A-F].
Counting in Hex is just as easy as in decimal or binary, the only difference is that the highest hexadecimal digit allowed is represented by the letter F.
hex - decimal
0001 - 1
0002 - 2
0003 - 3
0004 - 4
0005 - 5
0006 - 6
0007 - 7
0008 - 8
0009 - 9
000A - 10
000B - 11
000C- 12
000D - 13
000E - 14
000F - 15 <- highest hex digit allowed in base 16 is F, therefore 000F + 0001 = 0010
0010 - 16
0011 - 17
0012 - 18
....
00FF - 255
0100 - 256
....
0FFF - 4095
1000 - 4096
To convert from hex to decimal is very similar to converting from binary except the base (also called radix) is 16 not 2.
Observe that:
hex - decimal
0001 = 1 x 16^0 = 1
0010 = 1 x 16^1 = 16
0100 = 1 x 16^2 = 256
1000 = 1 x 16^3 = 4096
Meaning each column represents a power of 16.
So now it is possible to transform hex to decimal with relative ease:
1111(hex)= 1 x 16^0 + 1 x 16^1 + 1 x 16^2 + 1 x 16^3 = 1 + 16 + 256 + 4096 = 4369(decimal)
Slightly harder but not much, remember A = 10, B = 11, C = 12, D = 13
DCAC(hex) = 12 x 16^0 + 10 x 16^1 + 12 x 16^2 + 13 x 16^3 = 12 + 160 + 3072 + 53248 = 56492(decimal)
What is the decimal value of A8B7?
If you can answer, good job, now you can convert between hex and decimal.
One last thing to note regarding hex, the shorthand for hex can be the prefix 0x- which can be confusing as 0x18 actually means 18(hex) = 8 x 16^0 + 1 x 16^1 = 24(decimal) not 0; the key is noticing that there are no spaces indicating that 0x18 is a single number not an operation on a number.
-------------------------------------------------------------------------------
Now that you can count in binary and hex and convert them to decimal, it will be easy to do octal as there are no letters involved. Octal: Base 8 [0-7].
Octal - decimal
0000 - 0
0001 - 1 x 8^0 = 1
0002 - 2
0003 - 3
0004 - 4
0005 - 5
0006 - 6
0007 - 7 <- the highest digit allowed in base 8 so to add 1 to 0007(octal) must be 0010
0010 - 1 x 8^1 = 8
...
0100 - 1 x 8^2= 64
...
1000 - 1 x 8^3 = 512
1111(octal) = 1 x 8^0 + 1 x 8^1 + 1 x 8^2 + 1 x 8^3 = 512 + 64 + 8 + 1 = 585(decimal)
What is 5678(octal) in decimal?
If you can answer, good job, now you can convert between octal and decimal.
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|