Ok..let's see how easily I can do this using text :)
This is going to be messy but i'll try to simplify it as much as possible...
I'm going to start with Binary to decimal since it looks like you need the basics and it's better to start with this to do the others...
Given a binary string 110101
each bit represents a power of 2 starting from 0 until you run out of bits.. starting from right to left... so....
543210 <-- power of 2
110101
so...
2^0 * 1
2^1 * 0
2^2 * 1
2^3 * 0
2^4 * 1
2^5 * 1
and add.
1+0+4+0+16+32 = 53
for Binary to Octal:
Given Binary 1010101 you would split it up into groups of 3.
1,010,101 since the most significant side has only 1 bit left you can pad it with zeros to make it look nicer so 001,010,101
you would then break it down and convert them like we did for decimal. Each group of 5 represents a digit.
101 would be 5
010 would be 2
001 would be 1
so the final result is 125
for Binary to Hexdec:
Given the binary string 0101101
You would split it up into groups of 4
010, 1101
you can pad with 0s if you want to make it look nice or not.
now to convert
1101 would be d (13)
010 would be 2
so the result is 2d
Why 'd' instead of 13? for hexdecimal the digit ranges from 0-f.
0123456789abcdef so 13 is d.
to go backwards....
given decimal number 71
you would then start subtracting the largest power of 2 that'll fit inside 71. this is something you should try and know :)
1,2,4,8,16,32,64,128...
so 71-64 = 7
the next largest is 4 so 7-4=3
then 3-2=1 then 1-1=0
so 64,4,2,1 or 2^6,2^2,2^1,2^0
6543210 <-- power of 2
1000111 <-- result
For Hexdec to binary you basically do a similar conversion (it's actually a bit easier)
given hexdec value 5f:
you would convert each digit instead of doing it all at once...
convert 5 to 0101
convert f to 1111
result wold be 01011111
I'll leave octal to you :)
i hope this wasn't too messy...i know i thik it is :P
2007-02-28 12:17:15
·
answer #1
·
answered by mackn 3
·
1⤊
0⤋
Hi. A lot of calculators will do the conversion for you, but if it's only a few numbers then you can do them in your head. I'll explain. Take a binary byte number like 01000101. To convert to octal (base 8) break the number into groups of three. 01 000 101. Convert each group. (105o). For hex, break the number into groups of four (0100 0101). Convert each group (45h). Hope this is 1)right and 2) makes sense. Otherwise use the Google calculator or this table : http://www.ascii.cl/conversion.htm
2007-02-28 11:26:34
·
answer #2
·
answered by Cirric 7
·
0⤊
0⤋
To convert decimal to binary and decimal to octal using recursion (vb.net):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim int As Integer = Integer.Parse(LTrim(TextBox1.Text))
Dim result As String
lblBinOutput.Text = getBin(int)
lblOctOutput.Text = getOct(int)
End Sub
Private Function getBin(ByVal int As Integer) As String
Dim result As String
If int > 1 Then
result = getBin(int \ 2) & (int Mod 2).ToString
Else
If int = 0 Then
Return "0"
Else
Return "1"
End If
End If
Return result
End Function
Private Function getOct(ByVal int As Integer) As String
Dim result As String
If int > 7 Then
result = getOct(int \ 8) & (int Mod 8).ToString
Else
result = int Mod 8
End If
Return result
End Function
2007-02-28 12:20:24
·
answer #3
·
answered by BDZot 6
·
0⤊
0⤋
Look i will give you the table and i will explain to you how to do it if you remind me, write me to this email, katy_cruz6@yahoo.com... because now i'm at my work and i have that information at home....I had a class called logaritmos and was all about that!!!
2007-02-28 11:34:02
·
answer #4
·
answered by *COSI* 3
·
0⤊
0⤋