_BIN$
Jump to navigation
Jump to search
This function returns the binary (base 2) representation of any numeric value.
Syntax
- binvalue$ = _BIN$(number)
Parameters
- number can be any INTEGER, LONG or _INTEGER64 value, positive or negative.
- number can also be any SINGLE, DOUBLE or _FLOAT value, but only the integer part of the value is converted in that case. That is, from the value -123.45 the function would convert the -123 only.
Description
- The function returns the base 2 (binary) representation of the given number as STRING.
- Different from STR$, this function does not return a leading sign placeholder space, so no LTRIM$ to strip that space from positive numbers is necessary.
- VAL can convert the returned bin string value back to a decimal value by prefixing the string with "&B".
- Eg. decimal = VAL("&B" + binvalue$).
Availability
- QB64 2.1 and up (QB64 Team)
- QBPE 0.5 and up (QB64 Phoenix Edition)
Examples
- Example 1
- Comparing decimal, hexadecimal, octal and binary string values from 0 to 15.
tabletop$ = " Decimal | Hexadecimal | Octal | Binary " tablesep$ = "---------+-------------+-------+--------" tableout$ = " \ \ | \\ | \\ | \ \ " 'the PRINT USING template LOCATE 2, 10: PRINT tabletop$ LOCATE 3, 10: PRINT tablesep$ FOR n% = 0 TO 15 LOCATE 4 + n%, 10: PRINT USING tableout$; STR$(n%); HEX$(n%); OCT$(n%); _BIN$(n%) NEXT n% ;Note:Although the decimal numbers 0-15 have a maximum width of 2 digits only, an extra space in the tableout$ template is needed when using the (fixed width string) slash output format, as STR$ values contain a leading sign placeholder space.
See also
|