[002] - Number Conversions across various Number Systems (Part 1)

without comments

Numbers are represented using a variety of number systems, including Binary, Octal, Decimal, and Hexadecimal. However, they can be easily converted from one number system to another using simple procedures. In this post, I shall discuss how to achieve this.
One of the most important number conversions is converting a number to its decimal equivalent, and it is achieved by taking the sum of the face values of various digits multiplied by the radix
raised to the power of the index of the digit, starting from right. Yes, interpreting the value of a number is same as converting it into decimal form. For example :

(1101)_2= 1*2^3+1*2^2+0*2^1+1*2^0=(13)_10
(123)_8= 1*8^2+2*8^1+3*8^0=(83)_10
(8C5)_16= 8*16^2+12*16^1+5*16^0=(709)_10

To convert a decimal number, separate the integer and fraction part and convert each part separately. For example:
(456.20)_8= (456)_8+(0.20)_8
(456)_8= 4*8^2+5*8^1+6*8^0=(302)_10
(0.20)_8= 2*8^-1+0*8^0=(0.25)_10
doubleright (456.20)_8= (302.25)_10
Conversion from Decimal Numbers to Binary, Octal and Hexadecimal Numbers
The conversion from decimal to binary is done by repetitive division by 2 (the radix of binary). The procedure is simple - Take the binary number, divide it by 2, note the remainder, and divide the quotient again by 2. Continue until you get a zero as the quotient. Now, take the remainders, starting from the latest - stack them one after another and you get the binary number! Lets convert (41)_10 to binary:

tabular{00000000}{010}{41 ~ 20 1 10 0 5 0 2 1 1 0 0 1}

The elements in the second column contain the remainders obtained after repeated division by 2. Stack these remainders together, starting from down, to get the binary equivalent. Hence,

(41)_10= (101001)_2

To convert a fractional decimal part to a fractional binary part, we repeatedly multiply the fractional decimal part by two, until we get 1.0 as the result. Remember, only the fractional part is to be multiplied by 2. As an example, lets convert (0.6875)_10 to its binary equivalent:

tabular{0010101010}{00}{0.6875 ~*2 1.3750 ~*2 0.7500 ~*2 1.5000 ~*2 1.0000}

Here, the binary equivalent is obtained by stacking together the digits on the LHS of the decimal starting from the top. The first zero is ignored. Hence,

(0.6875)_10= (0.1011)_2

Hence, this is the way Decimal Numbers are converted to their Binary equivalents.
In order to convert Decimal Numbers to their Octal equivalents, replace 2 with 8 in the above calculations. Similarly, replace 2 with 16 for converting Decimal to Hexadecimal.

P.S. - My next post will deal with other conversions that are possible.

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • StumbleUpon
  • Technorati
  • TwitThis
  • Ma.gnolia
  • Google
  • Live
  • YahooMyWeb
  • E-mail this story to a friend!
  • Print this article!

Written by Rajat

August 10th, 2008 at 7:21 pm

Leave a Reply