Below function will do the string to HEX value conversion.

EFI_STATUS
StrtoHex (
    CHAR16 *String,
    UINT64 *HexValue
)
{
    UINT64 Value = 0;

    //Checking for ASCII value between '0' and 'F'
    while (TRUE) {
        if(*String >= '0' && *String <= '9') {
            Value *= HEX_TEN;
            Value += *String - '0';
        }
        else if(*String >= 'a' && *String <= 'f') {
            Value *= HEX_TEN;
            Value += (*String - 'a') + 10; // Convert to hex a-f
        }
        else if(*String >= 'A' && *String <= 'F') {
            Value *= HEX_TEN;
            Value += (*String - 'A') + 10; // Convert to hex a-f
        }
        else {
            break;
        }
        String++;
    }

    if (*String == '\0') {
        *HexValue = Value;
        return EFI_SUCCESS;
    }

    return EFI_INVALID_PARAMETER;
}

Thanks,
Ramesh

From: Carsey, Jaben [mailto:[email protected]]
Sent: Tuesday, September 09, 2014 12:34 AM
To: [email protected]
Subject: Re: [edk2] Get number from keyboard

There are some functions for converting strings to the number values they 
represent.  Look in shelllib.

-Jaben

From: Nguyễn Văn Hiễn [mailto:[email protected]]
Sent: Sunday, September 07, 2014 7:57 PM
To: [email protected]<mailto:[email protected]>
Subject: [edk2] Get number from keyboard

Hi all,
I'm writing an application running on Shell. It reads user's input (number) 
from keyboard to do somethings. But when I enter number 1, it gets the number 
49 (ASCII).
How can I get the input exactly?
ShellAppMain (
  IN UINTN    Argc,
  IN UINT64   **Argv
  )
{
  AtaDataTest.StartBlock = *Argv[1];
  DBG ("StartBlock: %d\n", AtaDataTest.StartBlock);
}
Thanks for any help,
Hien

=================
HCMUT
[email protected]<mailto:[email protected]>
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce.
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to