FutureBasic Logo

<<    Index    >> FutureBasic 5

bin$   function



Syntax:
binString$ = 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$ on some integer values. (If a non-integer expr is used, 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" + binaryString$)
intVar can be a (signed or unsigned) byte variable, short-integer variable or long-integer variable. Byte variables can handle a binaryString$ up to 8 characters in length; short-integer variables can handle a binaryString$ up to 16 characters in length; long-integer variable can handle a binaryString$ up to 32 characters in length.

See Also:
hex$; oct$; uns$; defstr byte/word/long; Appendix C - Data Types and Data Representation