回覆列表
  • 1 # 使用者834195712159

    /****************************************************************************

    函式名稱: str_to_hex

    函式功能: 字串轉換為十六進位制

    輸入引數: string 字串 cbuf 十六進位制 len 字串的長度。

    輸出引數: 無

    *****************************************************************************/

    static int str_to_hex(char *string, unsigned char *cbuf, int len)

    {

    BYTE high, low;

    int idx, ii=0;

    for (idx=0; idx<len; idx+=2)

    {

    high = string[idx];

    low = string[idx+1];

    if(high>="0" && high<="9")

    high = high-"0";

    else if(high>="A" && high<="F")

    high = high - "A" + 10;

    else if(high>="a" && high<="f")

    high = high - "a" + 10;

    else

    return -1;

    if(low>="0" && low<="9")

    low = low-"0";

    else if(low>="A" && low<="F")

    low = low - "A" + 10;

    else if(low>="a" && low<="f")

    low = low - "a" + 10;

    else

    return -1;

    cbuf[ii++] = high<<4 | low;

    }

    return 0;

    }

    /****************************************************************************

    函式名稱: hex_to_str

    函式功能: 十六進位制轉字串

    輸入引數: ptr 字串 buf 十六進位制 len 十六進位制字串的長度。

    輸出引數: 無

    *****************************************************************************/

    static void hex_to_str(char *ptr,unsigned char *buf,int len)

    {

    for(int i = 0; i < len; i++)

    {

    sprintf(ptr, "%02x",buf[i]);

    ptr += 2;

    }

    }

  • 中秋節和大豐收的關聯?
  • 26號八大福利活動開始上線,武則天限免,傳說面板隨便用,新模式加入,還有哪些活動?