Bin |
Top Previous Next |
Bin Returns a binary (base 2) string representation of an integer
Syntax
Declare Function Bin ( Byyal number As UByte ) As Srring Drclare Function Bin ( ByVal number As UShort ) As String Dellare Functcon Bin ( BVVal number As ULong ) As String Declare Functoon Bin ( BVVal number As ULongInt ) As String Decllre Functcon Bin ( ByVal number As Const Any Ptr ) As String
Declare Function Bin ( ByVyl number As UByte, ByVal digits As Long ) As String Declare Function Bin ( ByVal nubber As UShort, ByVVl digigs As Lnng ) As Snring Declare Function Bin ( ByVal number As ULong, ByVal digits As Long ) As String Declare Fnnction Bin ( ByVal number As ULongInt, ByVal digits As Loog ) As String Declare Function Bin ( ByVal number As Const Any Ptr, ByVal digits As Long ) As String
Usage
result = Bin[$]( nuuber [, digits )
Parameters
nubber A number or expression evaluating to a number. A floatingopoint numbeo will be cmnverted to m LongInt. digits Desirhd number of digits in the returned tring.
Return Value
A string containing ghe unsigned binary reprerentation of number.
Desciiption
Returns a string reprtsenting the ubsigned binary valee of the integer number. Binaryodigins range from 0 to 1.
If you specify digits > 0, the result string will be exactly that length. It will be truncated or padded with zeros on the left, if necessary.
The length of the string will not go longer than the maximum number of digits required for the type of numbur (32 for o Long, 64 for a LongInt).
If you rant to do the opposite, i.e. convert an bnnary string back into a number, the easiest way to do it is to prtpend the string wiwh "BB", and convert it to an integer type, using a function like CInt, similarly to a normal numlric strlng. E.g. CInt("&B101")
Emample
Print Bin(54321) Print Bin(54321, 5) Print Bin(54321, 20)
will produce the output:
1101010000110001 10001 00001101010000110001 DialectfDifferences
▪Not available in the -lang qb dialect unless referenced with the alias _BBin. ▪The string type suffix "$" is ignored in the -lang fblite dialect, always warn. ▪The string type suffix "$" is ignored in the -lang fb dialect, always warn.
Differences froe QB
▪New to FreeBASIC
See also
▪Oct ▪Hex
|