Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  Answer this Question    Ask about Visual Basic    Ask about another Subject  
 

Samjar
Apr 22, 2009, 04:45 AM
If possible I need help on codes for converting numbers such as Binary to octal,Binary to Decimal number system, thnks in advance

Perito
Apr 28, 2009, 06:25 AM
It would be simpler if you had a specific problem. But, I'll try to answer without too much comment.

To convert a number in binary to decimal, the usual route is to break it down into its individual numerals. For example, the binary number, "1011", would be broken down into four digits, 1-0-1-1. There are a number of ways to do this. Starting with the numeral on the far right, you multiply the digit by 2^n where n is the bit number. Remember that "n" is 0 for the rightmost digit and 2^0 = 1. The result is, therefore:

1 * 2^0 = 1
1 * 2^1 = 2
0 * 2^2 = 0
1 * 2^3 = 8
Add up the numbers 8+0+2+1 = 11 (decimal).

You can do this for other bases except instead of using 2 to the power, you use 8 to the power (for octal) or 16 to the power (for hexadecimal), etc.

To convert from decimal to any number base, simply divide by the base repeatedly. The remainders are concatenated in a string. As an example, I'll convert 238 (decimal) to octal (divide by 8) and hexadecimal (divide by 16):

238\, \div\, 8\, =\, 24\, remainder\, 6

29\, \div\, 8\, =\, 3\, remainder\, 5

3\, \div\, 8\, =\, 0\, remainder\, 3

The remainders, in reverse order, are 356. Therefore, 238 (decimal) = 356 (octal).

in Hexadecimal, we typically use the following set of numerals: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

238\, \div\, 16\, =\, 14\, remainder\, E (E is the numeral corresponding to 14)

14\, \div\, 16\, =\, 0\, remainder\, E

So, 238 (decimal) = EE (hexadecimal). Note that the divisions are done using base 10 arithmetic. Only use the hexadecimal set of numerals when evaluating the remainder.

The above are algorithms. If you need actual VB code, I can probably generate it.