Sign in for recommendations. New member? Start here.

VB Helper: HowTo: Convert values between decimal, hexadecimal,...

rtyucel rated 8 months agoFeatured Review
From the page: "Private Function BinaryToLong(ByVal binary_value As String) _ As Long Dim hex_result As String Dim nibble_num As Integer Dim nibble_value As Integer Dim factor As Integer Dim bit As Integer ' Remove any leading &B if present. ' (Note: &B is not a standard prefi...

Like this page from vb-helper.com?

2 Reviews

Characters left: 4000


TomHellier rated 8 months ago
Visual basics?! lol
rtyucel rated 8 months ago
From the page: "Private Function BinaryToLong(ByVal binary_value As String) _ As Long Dim hex_result As String Dim nibble_num As Integer Dim nibble_value As Integer Dim factor As Integer Dim bit As Integer ' Remove any leading &B if present. ' (Note: &B is not a standard prefix, it just ' makes some sense.) binary_value = UCase$(Trim$(binary_value)) If Left$(binary_value, 2) = "&B" Then binary_value = _ Mid$(binary_value, 3) ' Strip out spaces in case the bytes are separated ' by spaces. binary_value = Replace(binary_value, " ", "") ' Left pad with zeros so we have a full 32 bits. binary_value = Right$(String(32, "0") & binary_value, _ 32) ' Read the bits in nibbles from right to left. ' (A nibble is half a byte. No kidding!) For nibble_num = 7 To 0 Step -1 ' Convert this nibble into a hexadecimal string. factor = 1 nibble_value = 0 ' Read the nibble's bits from right to left. For bit = 3 To 0 Step -1 If Mid$(binary_value, 1 + nibble_num * 4 + bit, _ 1) = "1" Then nibble_value = nibble_value + factor End If factor = factor * 2 Next bit ' Add the nibble's value to the left of the ' result hex string. hex_result = Hex$(nibble_value) & hex_result Next nibble_num ' Convert the result string into a long. BinaryToLong = CLng("&H" & hex_result) End Function"