Convert Decimal Integer Values to Binary String in VB6

Convert Decimal Integer Values to Binary String in VB6

Public Function DecToBin(DeciValue As Long, Optional NoOfBits As Integer) _As String
 Dim i As Integer
 NoOfBits = 8
‘make sure there are enough bits to contain the number
 Do While DeciValue > (2 ^ NoOfBits) - 1 
 NoOfBits = NoOfBits + 8
 Loop
 DecToBin = vbNullString
‘build the string
For i = 0 To (NoOfBits - 1)    
DecToBin = CStr((DeciValue And 2 ^ i) / 2 ^ i) & DecToBin
Next i
End Function

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.