programming-examples/asp/FilesMaths/Hex to Bin.asp

37 lines
726 B
Plaintext
Raw Normal View History

2019-11-18 14:25:58 +01:00
Function HexToBin(hexvalue)
Dim i, s, ilen, value, values
Set values = CreateObject("Scripting.Dictionary")
values.Add "0", "0000"
values.Add "1", "0001"
values.Add "2", "0010"
values.Add "3", "0011"
values.Add "4", "0100"
values.Add "5", "0101"
values.Add "6", "0110"
values.Add "7", "0111"
values.Add "8", "1000"
values.Add "9", "1001"
values.Add "A", "1010"
values.Add "B", "1011"
values.Add "C", "1100"
values.Add "D", "1101"
values.Add "E", "1110"
values.Add "F", "1111"
value = Null
s = UCase(hexvalue)
If IsHex(s) Then
value = ""
ilen = Len(s)
For i = 1 To ilen
value = value & values(Mid(s, i, 1))
Next
End If
values.RemoveAll
Set values = Nothing
HexToBin = value
End Function