#1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default HEX2BIN

I have seen a few posting on this topic but they all have the same short
fall. I need a conversion that can handle a hex value from 00 to
FFFFFFFF7B00FF4000. I also need to maintain the leading 0's. 001 =
000000000001

Any ideas?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 266
Default HEX2BIN

"Dan" skrev i en meddelelse
...
I have seen a few posting on this topic but they all have the same short
fall. I need a conversion that can handle a hex value from 00 to
FFFFFFFF7B00FF4000. I also need to maintain the leading 0's. 001 =
000000000001

Any ideas?

Thanks


Hi Dan

This UDF will convert any hex number to its binary equivalent.

Function HexToBin(HStr As String) As String
'Leo Heuser, Sept. 2006
'Example: =hextobin("67F")
Dim Counter As Long
Dim Counter1 As Long
Dim Digits As String
Dim DStr As String
Digits = "0123456789ABCDEF"
HStr = UCase(HStr)

For Counter = Len(HStr) To 1 Step -1
DStr = InStr(Digits, Mid$(HStr, Counter, 1)) - 1
For Counter1 = 1 To 4
HexToBin = Mid$(Digits, DStr - Int(DStr / 2) * _
2 + 1, 1) & HexToBin
DStr = Int(DStr / 2)
Next Counter1
Next Counter

End Function

--
Best regards
Leo Heuser

Followup to newsgroup only please.



  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default HEX2BIN

Thanks Leo. Works perfectly.

"Leo Heuser" wrote:

"Dan" skrev i en meddelelse
...
I have seen a few posting on this topic but they all have the same short
fall. I need a conversion that can handle a hex value from 00 to
FFFFFFFF7B00FF4000. I also need to maintain the leading 0's. 001 =
000000000001

Any ideas?

Thanks


Hi Dan

This UDF will convert any hex number to its binary equivalent.

Function HexToBin(HStr As String) As String
'Leo Heuser, Sept. 2006
'Example: =hextobin("67F")
Dim Counter As Long
Dim Counter1 As Long
Dim Digits As String
Dim DStr As String
Digits = "0123456789ABCDEF"
HStr = UCase(HStr)

For Counter = Len(HStr) To 1 Step -1
DStr = InStr(Digits, Mid$(HStr, Counter, 1)) - 1
For Counter1 = 1 To 4
HexToBin = Mid$(Digits, DStr - Int(DStr / 2) * _
2 + 1, 1) & HexToBin
DStr = Int(DStr / 2)
Next Counter1
Next Counter

End Function

--
Best regards
Leo Heuser

Followup to newsgroup only please.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 266
Default HEX2BIN

You're welcome, Dan. Thanks for the feedback.

Leo Heuser


"Dan" skrev i en meddelelse
...
Thanks Leo. Works perfectly.

"Leo Heuser" wrote:

"Dan" skrev i en meddelelse
...
I have seen a few posting on this topic but they all have the same short
fall. I need a conversion that can handle a hex value from 00 to
FFFFFFFF7B00FF4000. I also need to maintain the leading 0's. 001 =
000000000001

Any ideas?

Thanks


Hi Dan

This UDF will convert any hex number to its binary equivalent.

Function HexToBin(HStr As String) As String
'Leo Heuser, Sept. 2006
'Example: =hextobin("67F")
Dim Counter As Long
Dim Counter1 As Long
Dim Digits As String
Dim DStr As String
Digits = "0123456789ABCDEF"
HStr = UCase(HStr)

For Counter = Len(HStr) To 1 Step -1
DStr = InStr(Digits, Mid$(HStr, Counter, 1)) - 1
For Counter1 = 1 To 4
HexToBin = Mid$(Digits, DStr - Int(DStr / 2) * _
2 + 1, 1) & HexToBin
DStr = Int(DStr / 2)
Next Counter1
Next Counter

End Function

--
Best regards
Leo Heuser

Followup to newsgroup only please.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default HEX2BIN

...I also need to maintain the leading 0's. 001

Just another of many variations:

Function HexToBin(HexString As String) As String
'// Dana DeLouis
Dim j As Long
Dim n As Long
Dim Bin As String

For j = Len(HexString) To 1 Step -1
n = Asc(UCase(Mid$(HexString, j, 1))) - 48 '0-9, or 17-22
If n 9 Then n = n - 7 '0-15
Bin = Sgn(n And 8) & Sgn(n And 4) & Sgn(n And 2) & Sgn(n And 1) &
Bin
Next j
HexToBin = Bin
End Function

--
Dana DeLouis
Windows XP, Office 2003


"Dan" wrote in message
...
I have seen a few posting on this topic but they all have the same short
fall. I need a conversion that can handle a hex value from 00 to
FFFFFFFF7B00FF4000. I also need to maintain the leading 0's. 001 =
000000000001

Any ideas?

Thanks





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HEX2BIN

Like your hextoBin but where are all the ole pascal binary type functions

like Number = bin

Shift left ( bits)
binary and or etc are they off in some macros somewhere

did you know that the nCr numbers in the group of r selected from n are
best represented by the n bit numbers that have r positive bits

Harry S




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HEX2BIN

I can't see the rest of the thread you are responding to, but I though
others reading it might be interested in this Decimal-To-Binary converter I
wrote awhile ago which will handle decimal values up to
79228162514264337593543950266 (approximately 96-bits) before issuing
screwing results or overflowing (you can also optionally specify the number
of bits to return)...

Function Dec2Bin(ByVal DecimalIn As Variant, _
Optional NumberOfBits As Variant) _
As String
Dec2Bin = ""
DecimalIn = CDec(DecimalIn)
Do While DecimalIn < 0
Dec2Bin = Trim$(Str$(DecimalIn - 2 * Int(DecimalIn / 2))) & Dec2Bin
DecimalIn = Int(DecimalIn / 2)
Loop
If Not IsMissing(NumberOfBits) Then
If Len(Dec2Bin) NumberOfBits Then
Dec2Bin = "Error - Number too large for bit size"
Else
Dec2Bin = Right$(String$(NumberOfBits, "0") & _
Dec2Bin, NumberOfBits)
End If
End If
End Function

Rick


"Harry Sorensen" <Harry wrote in message
...
Like your hextoBin but where are all the ole pascal binary type functions

like Number = bin

Shift left ( bits)
binary and or etc are they off in some macros somewhere

did you know that the nCr numbers in the group of r selected from n are
best represented by the n bit numbers that have r positive bits

Harry S





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default HEX2BIN

With some modification
This will list the groups in any nCr group selected from N
theory
the nCr items in groups of r selected from n things are indexed by the
binary numbers less than 2 ^n that have r positive bits
eg picking 4 from abcdefg
30 b0011110 is cdef
39 b0100111 is b efg
43 b0101011 is b d fg
so if you want all the combinations of 5 selected from 12
run 0 to 2^12-1 through the hex2bin and and keep or work from
those with 5 bits. ( for big nCr there are ways to speed this up so that
45C6 is practicable.

Function Dec2Bin(ByVal DecimalIn As Variant, _
NumBit As Integer, BitCou As Integer) As String
Dim Wdec As Currency
Dec2Bin = ""
BitCou = 0
DecimalIn = CCur(DecimalIn)
Do While DecimalIn < 0
Wdec = DecimalIn - 2 * Int(DecimalIn / 2)
If Wdec 0.1 Then BitCou = BitCou + 1
Dec2Bin = Trim$(Str$(Wdec)) & Dec2Bin
DecimalIn = Int(DecimalIn / 2)
Loop
Dec2Bin = "b" & _
Right$(String$(NumBit, "0") & _
Dec2Bin, NumBit) & "c"
End Function











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HEX2BIN Geo Excel Programming 3 August 27th 05 03:14 AM
Hex2Bin in VB kuch68 Excel Programming 4 April 13th 05 01:16 AM
hex2bin - HEX2BIN KarenSue33 Excel Programming 2 February 21st 05 07:11 PM


All times are GMT +1. The time now is 11:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"