Thread: HEX2BIN
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Harry Sorensen[_2_] Harry Sorensen[_2_] is offline
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