vba binary to decimal 8-bits

'Fast VBA function to converst binary string to a Long Integer:

Function BitsToLong&(bits$)
    Dim i&
    Static b() As Byte
    If LenB(bits) > 64 Then Exit Function
    If LenB(bits) = 64 Then
        b = bits
    Else
        b = String$(32 - Len(bits), "0") & bits
    End If
    For i = 2 To 62 Step 2
        BitsToLong = 2 * BitsToLong Or (b(i) Xor 48)
    Next
    If (b(0) Xor 48) Then BitsToLong = BitsToLong Or &H80000000
End Function

'-----------------------------------------------------------------------------

MsgBox BitsToLong("1")									'<--displays:  1    
MsgBox BitsToLong("10")									'<--displays:  2
MsgBox BitsToLong("0110")								'<--displays:  6
MsgBox BitsToLong("0100101")							'<--displays:  37
MsgBox BitsToLong("100000000000000000000")				'<--displays:  1048576
MsgBox BitsToLong("11111111111111111111111111111111")	'<--displays:  -1
    

4.29
7

                                    'Extremely fast VBA function to convert a binary string to a Byte:

Function BitsToByte(bits$) As Byte
    Dim i&amp;
    Static b() As Byte
    If LenB(bits) &gt; 16 Then Exit Function
    If LenB(bits) = 16 Then
        b = bits
    Else
        b = String$(8 - Len(bits), &quot;0&quot;) &amp; bits
    End If
    For i = 0 To 14 Step 2
        BitsToByte = 2 * BitsToByte Or (b(i) Xor 48)
    Next
End Function


'Example:

MsgBox BitsToByte(&quot;00001100&quot;)		'&lt;--displays: 12
MsgBox BitsToByte(&quot;10000001&quot;)		'&lt;--displays: 129
'
'
'

4.29 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
vba convert to byte array excel formula binary to decimal excel binary to decimal 16 bit excel vba byte to bits how to convert decimal to binary in casio fx-82ms binary to decimal excel excel binary to decimal 32 bit excel vba binary to hex excel binary to decimal xl vba long to binary excelvba long to binary excel vba long to binary vba long to bit string excel vba long to bit string vba specific bits set in byte excel vba are bits set in byte xl vba check if bit is set in 32-bit long integer excelvba check if bit is set in 32-bit long integer excel vba check if bit is set in 32-bit long integer excelvba is bit set long xlvba is bit set long xl vba is bit set long vba is bit set long excel vba is bit set long excel vba is bit set integer excel vba integer is bit set excel vba is bit set in integer vba is bit set in integer xlvba bit is set in byte xl vba bit is set in byte excelvba bit is set in byte excel vba bit is set in byte vba bit is set in byte excel vba is bit set in byte vba is bit set in byte xlvba set bit in byte xl vba set bit in byte excelvba set bit in byte excel vba set bit in byte excel vba binary string to short integer excel vba bits to integer excelvba binary to decimal 8-bits excel vba binary to decimal 8-bits xl vba binary to decimal 8-bits xlvba binary to decimal 8-bits vba binary to decimal 8-bits xlvba binary to decimal 8bits xl vba binary to decimal 8bits excel vba binary to decimal 8bits vba binary to decimal 8bits excelvba binary to decimal 8bits excelvba binary to byte 8bits excel vba binary to byte 8bits xl vba binary to byte 8bits xlvba binary to byte 8bits vba binary to byte 8bits xl vba binary to byte xlvba binary to byte excelvba binary to byte excel vba binary to byte vba binary to byte vba bin2dec 8-bits excelvba bit string to byte excel vba bit string to byte xl vba bit string to byte xlvba bit string to byte vba bit string to byte xlvba bits to byte xl vba bits to byte excel vba bits to byte excelvba bits to byte vba bits to byte vba print binary excel vba decimal to binary string excel-vba binary string to long excel vba binary string to long
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source