Syntax
binCFString =
bin(
expr )
binPascalString =
bin$(
expr )
Description
This function returns a string of zeros and ones representing the binary value of expr, in twos-complement integer format (the native format in which integers are stored). If defstr byte is in effect, an 8-character string will be returned. If defstr word is in effect, a 16-character string will be returned. If defstr long is in effect, a 32-character string will be returned.
Example
The chart below shows the results of bin/bin$ on some integer values. (If a non-integer expr is used, bin/bin$ converts it to an integer before generating the string.) The chart assumes that defstr word is in effect.
expr
|
bin( expr ) |
1
|
0000000000000001 |
-1
|
1111111111111111 |
256
|
0000000100000000 |
-256
|
1111111100000000 |
To convert a string of binary digits into an integer, use the following technique:
intVar = val&("&X" + binaryPascalString)
intVar
can be a (signed or unsigned) byte variable, short-integer variable or long-integer variable. Byte variables can handle a binaryPascalString
up to 8 characters in length; short-integer variables can handle a binaryPascalString
up to 16 characters in length; long-integer variable can handle a binaryPascalString
up to 32 characters in length.
See also
hex; oct; uns$; defstr; Appendix C - Data Types and Data Representation