Padded Binary String
#2
Code: (Select All)
'this allows a negative value padded by zeroes after sign
'set "numdig" to negative value to convert "num" to hexadecimal
'eg. "numdig = -6" to convert "num" to 6-digit hexadecimal string
FUNCTION Zeroes$ (num AS LONG, numdig AS INTEGER)
    STATIC b$, hx AS _BYTE, sg AS _BYTE, numd AS INTEGER, numi AS LONG, v AS LONG
    numi = num: numd = numdig
    IF numi < 0 THEN sg = -1: numi = numi * -1
    IF numd < 0 THEN hx = 1: numd = numd * -1 ELSE hx = 0
    IF hx THEN
        b$ = HEX$(numi)
    ELSE
        b$ = LTRIM$(STR$(numi))
    END IF
    v = numd - LEN(b$)
    IF v > 0 THEN b$ = STRING$(v, 48) + b$
    IF sg = -1 THEN b$ = "-" + b$
    Zeroes$ = b$
END FUNCTION

I needed it even more with hexadecimal numbers.
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: 8 Guest(s)