FreeBSD/sys/contrib/dev/acpica/components/executer/exconvrt.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExConvertToAscii
 *
 * PARAMETERS:  Integer         - Value to be converted
 *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
 *              String          - Where the string is returned
 *              DataWidth       - Size of data item to be converted, in bytes
 *
 * RETURN:      Actual string length
 *
 * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
 *
 ******************************************************************************/
AcpiExConvertToAscii
PARAMETERS:  Integer         - Value to be converted
Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
String          - Where the string is returned
DataWidth       - Size of data item to be converted, in bytes

Actual string length

Convert an ACPI Integer to a hex or decimal string
AcpiExConvertToAscii PARAMETERS : Integer - Value to be converted Base - ACPI_STRING_DECIMAL or ACPI_STRING_HEX String - Where the string is returned DataWidth - Size of data item to be converted in bytes Actual string length Convert an ACPI Integer to a hex or decimal string
static UINT32
AcpiExConvertToAscii (
    UINT64                  Integer,
    UINT16                  Base,
    UINT8                   *String,
    UINT8                   DataWidth)
{
    UINT64                  Digit;
    UINT32                  i;
    UINT32                  j;
    UINT32                  k = 0;
    UINT32                  HexLength;
    UINT32                  DecimalLength;
    UINT32                  Remainder;
    BOOLEAN                 SupressZeros;
    ACPI_FUNCTION_ENTRY ();
    switch (Base)
    {
    case 10:
        switch (DataWidth)
        {
        case 1:
            DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
            break;
        case 4:
            DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
            break;
        case 8:
        default:
            DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
            break;
        }
        SupressZeros = TRUE;     
        Remainder = 0;
        for (i = DecimalLength; i > 0; i--)
        {
            Digit = Integer;
            for (j = 0; j < i; j++)
            {
                (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
            }
            if (Remainder != 0)
            {
                SupressZeros = FALSE;
            }
            if (!SupressZeros)
            {
                String[k] = (UINT8) (ACPI_ASCII_ZERO + Remainder);
                k++;
            }
        }
        break;
    case 16:
        HexLength = ACPI_MUL_2 (DataWidth);
        for (i = 0, j = (HexLength-1); i < HexLength; i++, j--)
        {
            String[k] = (UINT8)
                AcpiUtHexToAsciiChar (Integer, ACPI_MUL_4 (j));
            k++;
        }
        break;
    default:
        return (0);
    }
    if (!k)
    {
        String [0] = ACPI_ASCII_ZERO;
        k = 1;
    }
    String [k] = 0;
    return ((UINT32) k);
}
static UINT32 AcpiExConvertToAscii ( UINT64 Integer , UINT16 Base , UINT8 * String , UINT8 DataWidth ) { UINT64 Digit ; UINT32 i ; UINT32 j ; UINT32 k = 0 ; UINT32 HexLength ; UINT32 DecimalLength ; UINT32 Remainder ; BOOLEAN SupressZeros ; ACPI_FUNCTION_ENTRY ( ) ; switch ( Base ) { case 10 : switch ( DataWidth ) { case 1 : DecimalLength = ACPI_MAX8_DECIMAL_DIGITS ; break ; case 4 : DecimalLength = ACPI_MAX32_DECIMAL_DIGITS ; break ; case 8 : default : DecimalLength = ACPI_MAX64_DECIMAL_DIGITS ; break ; } SupressZeros = TRUE ; Remainder = 0 ; for ( i = DecimalLength ; i > 0 ; i -- ) { Digit = Integer ; for ( j = 0 ; j < i ; j ++ ) { ( void ) AcpiUtShortDivide ( Digit , 10 , & Digit , & Remainder ) ; } if ( Remainder != 0 ) { SupressZeros = FALSE ; } if ( ! SupressZeros ) { String [ k ] = ( UINT8 ) ( ACPI_ASCII_ZERO + Remainder ) ; k ++ ; } } break ; case 16 : HexLength = ACPI_MUL_2 ( DataWidth ) ; for ( i = 0 , j = ( HexLength - 1 ) ; i < HexLength ; i ++ , j -- ) { String [ k ] = ( UINT8 ) AcpiUtHexToAsciiChar ( Integer , ACPI_MUL_4 ( j ) ) ; k ++ ; } break ; default : return ( 0 ) ; } if ( ! k ) { String [ 0 ] = ACPI_ASCII_ZERO ; k = 1 ; } String [ k ] = 0 ; return ( ( UINT32 ) k ) ; }
FUNCTION:    AcpiExConvertToAscii
 PARAMETERS:  Integer         - Value to be converted
              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
              String          - Where the string is returned
              DataWidth       - Size of data item to be converted, in bytes
FUNCTION : AcpiExConvertToAscii PARAMETERS : Integer - Value to be converted Base - ACPI_STRING_DECIMAL or ACPI_STRING_HEX String - Where the string is returned DataWidth - Size of data item to be converted in bytes
/* Setup max length for the decimal number */ /* No leading zeros */ /* Divide by nth factor of 10 */ /* Handle leading zeros */ /* HexLength: 2 ascii hex chars per data byte */ /* Get one hex digit, most significant digits first */ /*
     * Since leading zeros are suppressed, we must check for the case where
     * the integer equals 0
     *
     * Finally, null terminate the string and return the length
     */