Futurebasic/Language/Reference/binstring
Contents |
[edit] Bin$
[edit] Function
✔ Appearance ✔ Standard ✔ Console
[edit] Syntax
binString$ = bin$( expr )
[edit] Description
This function returns a string of zeros and ones representing the binary value of expr, in "two's-complement integer" format (this is the native format in which integers are stored in FB). 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.
[edit] 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. 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.
[edit] Notes
No special notes.
[edit] See Also
hex$; oct$; UNS$; destr byte/word/long; Appendix C: Data Types and Data Representation
This page may need to be