dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 03 May 2008, 16:15 PM Post subject: |
|
|
| stevech wrote: | | pretty simple to code a function to do it. |
Here's an example for Byte values that is written to be easily modified to handle 16-bit or 32-bit values.
| Code: | Function CStrBinByte(ByVal val as Byte) as String
Const bitCnt as Integer = SizeOf(val) * 8
Dim buf(1 to bitCnt) as Byte
Dim i as Integer
For i = bitCnt to 1 Step -1
buf(i) = IIF(CBool(LoByte(val) And 1), Asc("1"), Asc("0"))
val = Shr(val, 1)
Next i
CStrBinByte = MakeString(buf.DataAddress, bitCnt)
End Function |
Modified to handle Integer values:
| Code: | Function CStrBinInt(ByVal val as Integer) as String
Const bitCnt as Integer = SizeOf(val) * 8
Dim buf(1 to bitCnt) as Byte
Dim i as Integer
For i = bitCnt to 1 Step -1
buf(i) = IIF(CBool(LoByte(val) And 1), Asc("1"), Asc("0"))
val = Shr(val, 1)
Next i
CStrBinInt = MakeString(buf.DataAddress, bitCnt)
End Function |
|
|