Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Función que convierte de decimal a binario
- Public Function ConvertirDecimalABinario(ByVal NumeroDecimal As String) As String
- decimalABinario = ""
- NumeroDecimal = Int(CDec(NumeroDecimal))
- Do While NumeroDecimal <> 0
- decimalABinario = Format$(NumeroDecimal - 2 * Int(NumeroDecimal / 2)) & decimalABinario
- NumeroDecimal = Int(NumeroDecimal / 2)
- Loop
- MsgBox (decimalABinario)
- End Function
- 'Función que convierte de binario a decimal
- Function ConvertirBinarioADecimal(numeroBinario As String) As Variant
- Dim X As Integer
- Dim NumeroDecimal As Integer
- For X = 0 To Len(numeroBinario) - 1
- NumeroDecimal = NumeroDecimal + Val(Mid(numeroBinario, Len(numeroBinario) - X, 1)) * 2 ^ X
- Next
- MsgBox (NumeroDecimal)
- End Function
- 'Función que convierte de decimal a hexadecimal
- Public Function ConvertirDecimalAHexadecimal(ByVal Dec As Double) As String
- Dim i As Long
- Dim n As Long
- Dim posicionValorHexadecimal As Long
- Dim Hex(1 To 256) As String
- Dim HexTemp As String
- Dim Divisor As Long
- Dec = Int(Dec)
- For i = 256 To 2 Step -1
- If Dec >= 16 ^ (i - 1) And Dec > 15 Then
- posicionValorHexadecimal = Int(Dec / (16 ^ (i - 1)))
- Dec = Dec - (16 ^ (i - 1)) * posicionValorHexadecimal
- Select Case posicionValorHexadecimal
- Case 0 To 9
- Hex(i) = CStr(posicionValorHexadecimal)
- Case Is = 10
- Hex(i) = "A"
- Case Is = 11
- Hex(i) = "B"
- Case Is = 12
- Hex(i) = "C"
- Case Is = 13
- Hex(i) = "D"
- Case Is = 14
- Hex(i) = "E"
- Case Is = 15
- Hex(i) = "F"
- End Select
- Else
- Hex(i) = "0"
- End If
- Next i
- posicionValorHexadecimal = Dec
- Select Case posicionValorHexadecimal
- Case 0 To 9
- Hex(1) = CStr(posicionValorHexadecimal)
- Case Is = 10
- Hex(1) = "A"
- Case Is = 11
- Hex(1) = "B"
- Case Is = 12
- Hex(1) = "C"
- Case Is = 13
- Hex(1) = "D"
- Case Is = 14
- Hex(1) = "E"
- Case Is = 15
- Hex(1) = "F"
- End Select
- For i = 256 To 1 Step -1
- If Hex(i) = "0" Then
- Else
- n = i
- Exit For
- End If
- Next i
- For i = n To 1 Step -1
- HexTemp = HexTemp & Hex(i)
- Next i
- DecToHex = HexTemp
- MsgBox (DecToHex)
- End Function
- 'Función que convierte de binario a decimal
- Function ConvertirHexadecimalADecimal(ByVal numeroHexadecimal As String) As String
- Dim X As Integer
- Dim NumeroDecimal As Long
- NumeroDecimal = 0
- For X = 0 To Len(numeroHexadecimal) - 1
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "A") = 0 Then
- NumeroDecimal = NumeroDecimal + 10 * 16 ^ X
- End If
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "B") = 0 Then
- NumeroDecimal = NumeroDecimal + 11 * 16 ^ X
- End If
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "C") = 0 Then
- NumeroDecimal = NumeroDecimal + 12 * 16 ^ X
- End If
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "D") = 0 Then
- NumeroDecimal = NumeroDecimal + 13 * 16 ^ X
- End If
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "E") = 0 Then
- NumeroDecimal = NumeroDecimal + 14 * 16 ^ X
- End If
- If StrComp(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1), "F") = 0 Then
- NumeroDecimal = NumeroDecimal + 15 * 16 ^ X
- End If
- If IsNumeric(Mid(numeroHexadecimal, Len(numeroHexadecimal) - X, 1)) Then
- NumeroDecimal = 1
- End If
- Next
- Dim cadena As String
- cadena = CStr(1231235)
- MsgBox (CStr(NumeroDecimal))
- End Function
- 'Función que convierte de decimal a octal
- Public Function ConvertirDecimalAOctal(ByVal NumeroDecimal As String) As String
- decimalAOctal = ""
- NumeroDecimal = Int(CDec(NumeroDecimal))
- Do While NumeroDecimal <> 0
- decimalAOctal = Format$(NumeroDecimal - 8 * Int(NumeroDecimal / 8)) & decimalAOctal
- NumeroDecimal = Int(NumeroDecimal / 8)
- Loop
- MsgBox (decimalAOctal)
- End Function
- 'Función que convierte de octal a decimal
- Function ConvertirOctalADecimal(numeroOctal As String) As Variant
- Dim X As Integer
- Dim NumeroDecimal As Integer
- For X = 0 To Len(numeroOctal) - 1
- NumeroDecimal = NumeroDecimal + Val(Mid(numeroOctal, Len(numeroOctal) - X, 1)) * 8 ^ X
- Next
- MsgBox (NumeroDecimal)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement