Any1 can help me to do some correction as when i run my programming, if i put 54 1's for my binary input. the out put were bcome an error. If less than 54 1's there were no error and can convert to hex. Is there any idea to create that i can input infinite binary and convert to hex?
Module Module1
Sub Main()
Dim s AsString
Dim formatStr AsString
Console.Write("Please enter a binary: ")
s = Console.ReadLine()
formatStr = String.Format("hex number is:{0}", BinToHex(s))
Console.WriteLine(formatStr)
Console.ReadLine()
EndSub
Function BinToHex(ByVal BinNum AsString) AsString
Dim BinLen AsInteger, i AsDouble
Dim HexNum AsObject
OnErrorGoTo ErrorHandler
BinLen = Len(BinNum)
For i = BinLen To 1 Step -1
If Asc(Mid(BinNum, i, 1)) < 48 Or _
Asc(Mid(BinNum, i, 1)) > 49 Then
HexNum = ""
Err.Raise(1002, "BinToHex", "Invalid output")
EndIf
If Mid(BinNum, i, 1) And 1 Then
HexNum = HexNum + 2 ^ Abs(i - BinLen)
EndIf
Next i
BinToHex = Hex(HexNum)
ErrorHandler:
EndFunction
EndModule