vbs-二進制轉16進制

'二進制轉16進制
'binary二進制字符串
Function binaryToHex(binary)
	binary_len = len(binary)
	quyu = binary_len mod 4
	If quyu <> 0 then 
		ss = 5/0
	End If
	hex_len = binary_len/4
	For i = 1 To hex_len
		start_index = (i-1)*4+1
		binary_sub = mid(binary,start_index,4)
		hex_str = ""
		If binary_sub = "0000" then hex_str = "0"
		If binary_sub = "0001" then hex_str = "1"
		If binary_sub = "0010" then hex_str = "2"
		If binary_sub = "0011" then hex_str = "3"
		If binary_sub = "0100" then hex_str = "4"
		If binary_sub = "0101" then hex_str = "5"
		If binary_sub = "0110" then hex_str = "6"
		If binary_sub = "0111" then hex_str = "7"
		If binary_sub = "1000" then hex_str = "8"
		If binary_sub = "1001" then hex_str = "9"
		If binary_sub = "1010" then hex_str = "a"
		If binary_sub = "1011" then hex_str = "b"
		If binary_sub = "1100" then hex_str = "c"
		If binary_sub = "1101" then hex_str = "d"
		If binary_sub = "1110" then hex_str = "e"
		If binary_sub = "1111" then hex_str = "f"
		binaryToHex = binaryToHex & hex_str
	Next
End Function

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章