Decimal to Binary Conversion Visual Basic
Decimal digits arranged over 10 pieces ie 0,1,2,3,4,5,6,7,8,9. Because the constituent digits as much as 10 it is called a base 10 number system. How do I get the base 10 number system is converted into binary systems based on 2 (0 da 1)? This can be done by performing division of decimal numbers with 2 to decimal numbers are smaller than 2. Binary number is the remainder of the division. Suppose there is decimal 10, binary numbers are:
10: 2 = 5 remainder 0
5: 2 = 2 remainder 1
2: 2 = 1 remainder 0
1: 2 = 0 remainder 1
thus obtained binary number is 1010.
Suppose again there are 65 decimal then the conversion to binary is:
65: 2 = 32 remainder 1
32: 2 = 16 remainder 0
16: 2 = 8 remainder 0
8: 2 = 4 remainder 0
4: 2 = 2 remainder 0
2: 2 = 1 remainder 0
1: 2 = 0 remainder 1
thus obtained binary 1000001
We note that every decimal numbers divided by 2. Time sharing is a binary digit. The division is done continuously until the quotient is smaller than 2. Binary number composed of the rest of the division of the latter.
Algorithm
0.mulai
1.Tentukan decimal numbers, eg: N as the numerator
2. Determine the number of denominators, eg, X; Set Binary = ""
3. Repeat For N> X do
Results = N Div X
Time = N Mod 2
N = Result
Binary = Binary + Time
4. Back to 3
5. Binary Print
6. Completed
Implementation
Private Sub Form_Activate ()
Dim N, X, Left, I, Length As Byte
Dim Binary As String
N = 65 'Decimal Numbers
Binary = ""
While N> X
Results = N Div X
Time = N Mod X
Binary = Binary + Time
N = Result
Wend
Binary Print
End Sub
Monday, June 6, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment