Integer numbers en binary string

Estado
Cerrado para nuevas respuestas.

Shura

Dragón Ancestral Lvl 2
Description: este codigo comvierte integer numbers en binary string en la formula '101010' y vice versa.

Keywords: Binary numbers, binary numbering system, integer numebrs, long integer, decimal numbering system.



Function IntToBin(ByVal IntegerNumber As Long)

IntNum = IntegerNumber
Do
'Use the Mod operator to get the current binary digit from the
'Integer number
TempValue = IntNum Mod 2
BinValue = CStr(TempValue) + BinValue

'Divide the current number by 2 and get the integer result
IntNum = IntNum \ 2
Loop Until IntNum = 0

IntToBin = BinValue

End Function

Function BinToInt(ByVal BinaryNumber As String)

'Get the length of the binary string
Length = Len(BinaryNumber)

'Convert each binary digit to its corresponding integer value
'and add the value to the previous sum
'The string is parsed from the right (LSB - Least Significant Bit)
'to the left (MSB - Most Significant Bit)
For x = 1 To Length
TempValue = TempValue + Val(Mid(BinaryNumber, Length - x + 1, 1)) * 2 ^ (x - 1)
Next

BinToInt = TempValue

End Function
--------------------------------------------------------------------------------
Private Sub Command1_Click()
'Text1 contains the integer number. Text2 shows the binary result
Text2.Text = IntToBin(Val(Text1.Text))
End Sub
--------------------------------------------------------------------------------
Private Sub Command2_Click()
'Text3 contains the binary string. Text4 shows the integer result
Text4.Text = BinToInt(Text3.Text)
End Sub

Este material no es mio fue exreaido de otra web su idioma original era ingles traducccion fea por shura xD, no ponga la web de la q lo saque porq habia materiales q se les podia dar mal uso ^^.

suerte a todos y espero q les sirva
 
Estado
Cerrado para nuevas respuestas.
Arriba