Yet another feature request
Yet another feature request
It would be nice to have a CStrBin(var) to convert a variable to a binary string.
Here's an example for Byte values that is written to be easily modified to handle 16-bit or 32-bit values.stevech wrote:pretty simple to code a function to do it.
Code: Select all
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
Code: Select all
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
- Don Kinzer