Navigation: thinBasic Modules > Core > String handling > BIN$ |
|
Description
Return a string that is the binary (base 2) representation of its argument.
Syntax
s = BIN$(NumericExpression [, Digits])
Returns
String
Parameters
Name |
Type |
Optional |
Meaning |
NumericExpression |
Number |
No |
The numeric expression you want transform into binary format. |
Digits |
Number |
Yes |
If digits is specified, the resulting string will be of length digits. |
Remarks
Restrictions
See also
Examples
Thanks to Abraxas for the following script example
'---Usage of the BIN$ Instruction example
'---Returns Binary Version of a number
Dim Base10Num As DWORD VALUE &hAAAA5555
Dim TempVal As DWORD VALUE Base10Num
Dim n As Byte VALUE 0
Dim sMsg As String
sMsg += "Base10 = " & Base10Num & $CRLF
sMsg += "Binary = " & Bin$(Base10Num,32) & $CRLF
sMsg += "Binary Nibbles = "
'---This Groups 4 bits (a nibble)
For n = 28 To 0 Step -4
TempVal = Base10Num
sMsg += " " & Bin$((SHIFT SIGNED RIGHT TempVal,n),4)
Next
sMsg += $CRLF
sMsg += "Hex = &h" & Hex$(Base10Num,8)
MSGBOX 0, sMsg '---Display The information
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |