From: Pierre Gondois <[email protected]> Add HexFromAscii(), converting an hexadecimal ascii char to an integer.
Signed-off-by: Pierre Gondois <[email protected]> --- .../Include/Library/AcpiHelperLib.h | 14 +++++++++ .../Library/Common/AcpiHelperLib/AcpiHelper.c | 30 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h index b653c3cb69ef..eec0cf75e084 100644 --- a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h +++ b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h @@ -33,6 +33,20 @@ AsciiFromHex ( IN UINT8 Hex ); +/** Convert an ASCII char representing an hexadecimal number + to its integer value. + + @param [in] Char Char to convert. + Must be between '0'-'9' or 'A'-'F' or 'a'-'f'. + + @return The corresponding integer (between 0-16). +**/ +UINT8 +EFIAPI +HexFromAscii ( + IN CHAR8 Char + ); + /** Check if a HID is a valid PNP ID. @param [in] Hid The Hid to validate. diff --git a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c index 19840fb173eb..c7097c8ff432 100644 --- a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c +++ b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c @@ -37,6 +37,36 @@ AsciiFromHex ( return (UINT8)-1; } +/** Convert an ASCII char representing an hexadecimal number + to its integer value. + + @param [in] Char Char to convert. + Must be between '0'-'9' or 'A'-'F' or 'a'-'f'. + + @return The corresponding integer (between 0-16). +**/ +UINT8 +EFIAPI +HexFromAscii ( + IN CHAR8 Char + ) +{ + if ((Char >= '0') && (Char <= '9')) { + return (UINT8)(Char - '0'); + } + + if ((Char >= 'A') && (Char <= 'F')) { + return (UINT8)(Char - 'A' + 10); + } + + if ((Char >= 'a') && (Char <= 'f')) { + return (UINT8)(Char - 'a' + 10); + } + + ASSERT (FALSE); + return (UINT8)-1; +} + /** Check if a HID is a valid PNP ID. @param [in] Hid The Hid to validate. -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#76933): https://edk2.groups.io/g/devel/message/76933 Mute This Topic: https://groups.io/mt/83735187/21656 Group Owner: [email protected] Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
