前言:
今天我们对“字符转16进制java”可能比较注重,各位老铁们都需要剖析一些“字符转16进制java”的相关文章。那么小编也在网络上汇集了一些对于“字符转16进制java””的相关文章,希望小伙伴们能喜欢,小伙伴们快快来学习一下吧!为了方便实际应用做了个16进制的字符串转16进制的数组,代码如下:
void net_data_depack_from_hex_string(char *p_data_hex_char)
{
charbuf_str[1024];
UINT16buf_str_len = 0;
UINT16i;
UINT16count = 0;
for (i = 0; p_data_hex_char[i] != '\0'; i++ )
{
if (p_data_hex_char[i] >= 'a' && p_data_hex_char[i] <= 'f')
{
if (0x01 == (count & 0x01))
{
buf_str[buf_str_len] = (buf_str[buf_str_len] << 4) | (p_data_hex_char[i] - 0x57);
buf_str_len++;
}
else
{
buf_str[buf_str_len] = p_data_hex_char[i] - 0x57;
}
count++;
}
else if (p_data_hex_char[i] >= 'A' && p_data_hex_char[i] <= 'F')
{
if (0x01 == (count & 0x01))
{
buf_str[buf_str_len] = (buf_str[buf_str_len] << 4) | (p_data_hex_char[i] - 0x37);
buf_str_len++;
}
else
{
buf_str[buf_str_len] = p_data_hex_char[i] - 0x37;
}
count++;
}
else if (p_data_hex_char[i] >= '0' && p_data_hex_char[i] <= '9')
{
if (0x01 == (count & 0x01))
{
buf_str[buf_str_len] = (buf_str[buf_str_len] << 4) | (p_data_hex_char[i] - '0');
buf_str_len++;
}
else
{
buf_str[buf_str_len] = p_data_hex_char[i] - '0';
}
count++;
}
}
LOG_INFO("buf_str_len=%u,", buf_str_len);
cz_hex_dump((UINT8 *)buf_str, (INT32)buf_str_len, "buf_str");
{
UDZ_Head_tudz_head;
UINT8data_buf[WAN_PACK_MAX_LEN];
UINT16data_len = 0;
if (0 == net_data_depack((Net_Pack_t*)buf_str, &udz_head, data_buf, &data_len))
{
LOG_INFO("depack success,datalen=%u,", data_len);
cz_hex_dump((UINT8 *)&udz_head, sizeof(udz_head), "depack_udz_head content:");
cz_hex_dump(data_buf, data_len, "depack content:");
}
else
{
LOG_ERROR("fail:net data depack,buf_str_len=%u,", buf_str_len);
cz_hex_dump((UINT8 *)buf_str, buf_str_len, "depack content:");
}
}
}
标签: #字符转16进制java