&B
Jump to navigation
Jump to search
The &B prefix denotes that an integer value is expressed in a Binary base 2 format. Every 8 digits represent a _BYTE.
Syntax
- a& = &B10010110
Description
- The base 2 numbering system uses binary digit values of 0 and 1 only.
- Leading zero values can be omitted just like in decimal values as they add nothing to the return value.
- Decimal values returned can be any signed INTEGER, LONG integer, or _INTEGER64 value so use those type of variables when converting directly as shown above in the Syntax. The program "overflow" error limits are listed as:
- _BYTE: 8 binary digits or a decimal value range from -128 to 127. _UNSIGNED: 0 to 255.
- INTEGER: 16 binary digits or a decimal value range from -32,768 to 32,767. _UNSIGNED: 0 to 65535.
- LONG: 32 binary digits or a decimal value range from -2,147,483,648 to 2,147,483,647. _UNSIGNED: 0 to 4294967295.
- _INTEGER64: 64 binary digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
- _UNSIGNED _INTEGER64: 0 to 18446744073709551615.
- The maximum binary value for each numerical type is the maximum number of digits listed above, each valued at 1.
- Convert binary to LONG values by appending the values with the suffix &. Example: &B1000000000000000 = -32768: &B1000000000000000& = 32768
- To convert binary strings returned from _BIN$ with VAL you need to prefix the string with &B (for example, if the string is "1101" you should do VAL("&B1101") or VAL("&B" + binvalue$).
Examples
- Example 1
- The maximum binary values of decimal value -1 in each numerical type are:
c&& = -1: d& = -1: e% = -1: f%% = -1 bi$ = _BIN$(f%%) PRINT "Max binary _BYTE = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(e%) PRINT "Max binary INTEGER = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(d&) PRINT "Max binary LONG = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(c&&) PRINT "Max binary _INTEGER64 = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(9223372036854775807) PRINT "Max _INTEGER64 value = "; bi$; " with"; LEN(bi$); "digits" bi$ = _BIN$(-9223372036854775808) PRINT "Min _INTEGER64 value = "; bi$; " with"; LEN(bi$); "digits" |
Max binary _BYTE = 11111111 with 8 digits = 255 Max binary INTEGER = 1111111111111111 with 16 digits = 65535 Max binary LONG = 11111111111111111111111111111111 with 32 digits = 4294967295 Max binary _INTEGER64 = 1111111111111111111111111111111111111111111111111111111111111111 with 64 digits =-1 Max _INTEGER64 value = 111111111111111111111111111111111111111111111111111111111111111 with 63 digits Min _INTEGER64 value = 1000000000000000000000000000000000000000000000000000000000000000 with 64 digits |
See also