|
-
Mar 14th, 2012, 10:42 AM
#1
Thread Starter
New Member
Decimal to Binary
hello,
i am trying to do Decimal to 7bit binary conversion, my function is working fine when i use it in excel, but when i include it to a sub routine, i only shows 1 digit,
Function dectobin1(DeciValue As Long, Optional NoOfBits As Integer = 7) As String
Dim i As Integer
Do While DeciValue > (2 ^ NoOfBits) - 1
NoOfBits = NoOfBits + 8
Loop
dectobin1 = vbNullString
For i = 0 To (NoOfBits - 1)
dectobin1 = CStr((DeciValue And 2 ^ i) / 2 ^ i) & dectobin1
Next i
End Function
Sub generate()
Dim dec(1 To 100) As Integer
Dim bin(1 To 100) As String
Dim i As Long
For i = 1 To 100 Step 1
Sheet1.Cells(13 + i, 1).Value = i
bin(i) = dectobin1(i)
Sheet1.Cells(13 + i, 4).Value = bin(i)
Next i
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|