Miscellaneous Routines

Click on a routine name to see the source

 digit(bin,n)
       
Return a specified digit from a number 

Parameters: 

bin       - the number to process
n  
       - the digit (0 being rightmost digit) to extract

Returns:
           
a ubyte containing the digit

 Example: 

X = 29876
Digit(x,0) returns 6
Digit(x,5) returns 2

 

PadStrHex(var, string, [length], [char])
   
     Converts data to hex, optionally padding on the left with a character 

Parameters: 

Var       - the variable to convert. May be of any type (byte, integer, etc)
string
   - a string variable into which the conversion will take place
Length
- optional. If specified, the resulting hex string will be this length, padded on the left with the specified character. If omitted, no padding will be done.
Char    - 
optional. If specified, the character that will be used for padding. If omitted, “0” will be used. 

ShrS(bin, bits)
       
Shift Right Signed: does an arithmetic right shift, preserving the sign bit. The standard shift right clears the high order bits as it shifts. 

Parameters:

Bin       - the signed variable to shift (byte, integer, short or long
Bits     
- the number of bits to shift.

Example:

            DIM x as integer
            X = -16
            ShrS(x,2) gives –4          (0xFFF0 becomes 0xFFFC)
            Shr(x,2)  gives 16380      (0xFFF0 becomes 0x3FFC)