Thread: HEX2BIN
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1904_] Rick Rothstein \(MVP - VB\)[_1904_] is offline
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