Padded Binary String
#1
A function to create a padded binary string.
if _bin$ would return "10"   this can return "00000010"

EDIT:  corrected a typo in function the demo let slip past but using this in another program exposed the error. All good now.

Code: (Select All)
'binpad$
' written with qb64PE 0.8.2
'a function to pad strings for binary values of numbers with leadiing 0's
'
Print "Enter a number and the binary string will be returned"
Do
    Input "Enter a number from 0 to 255 (-1 to exit) :", n
    If n > -1 And n < 256 Then
        bb = n
        Print
        Print "Integer: "; n
        bt$ = binpad$(n, 8)

        Print "Binary:"; bt$
        _Clipboard$ = bt$ 'write the string to the clipbaord
    End If

Loop Until n = -1
Print "BYE."
'===================================================================================
Function binpad$ (b, d)
    'binpad$ returns a string of a binary value
    'leading 0's will be inserted to pad a string to the minimum size of d characters
    'b is the binary value
    'd is digits to display
    bt$ = _Bin$(b)
    If Len(bt$) < d Then
        c = d - Len(bt$)
        bt$ = String$(c, Asc("0")) + bt$
    End If
    binpad$ = bt$
End Function
Reply


Messages In This Thread
Padded Binary String - by James D Jarvis - 08-25-2022, 12:35 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 01:45 AM
RE: Padded Binary String - by James D Jarvis - 08-25-2022, 01:50 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 01:56 AM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:27 AM
RE: Padded Binary String - by Pete - 08-25-2022, 04:53 AM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:59 AM
RE: Padded Binary String - by Pete - 08-25-2022, 06:12 AM
RE: Padded Binary String - by RhoSigma - 08-25-2022, 08:19 AM
RE: Padded Binary String - by mnrvovrfc - 08-25-2022, 03:12 PM
RE: Padded Binary String - by bplus - 08-25-2022, 04:17 PM
RE: Padded Binary String - by bplus - 08-25-2022, 04:21 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 06:18 PM
RE: Padded Binary String - by RhoSigma - 08-25-2022, 04:36 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 04:30 PM
RE: Padded Binary String - by bplus - 08-25-2022, 07:51 PM
RE: Padded Binary String - by SMcNeill - 08-25-2022, 08:03 PM



Users browsing this thread: 10 Guest(s)