https://blog.csdn.net/qq_39412582/article/details/81433339
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int Check_sys()
{
union Un
{
char c;
int i;
}un;
un.i = 1;
return un.c;
}
static void print_hex(const unsigned char *p_data, const int len)
{
if(NULL == p_data || len < 0)
{
return;
}
unsigned char data[4096] = {0};
for(int i = 0; i < len; i++)
{
snprintf((char*)data+strlen((char*)data), sizeof(data)-strlen((char*)data), "%02x", p_data[i]);
}
printf("adas_client print_hex:%s\n", data);
}
int main()
{
int ret=Check_sys();
if (1 == ret)
{
printf("当前模式为小端存储\n");
}
else
{
printf("当前模式为大端存储\n");
}
float hei = 6.89;
printf("hei:%f %x\n", hei, hei);
print_hex((const unsigned char *)&hei,4);
double latitude = 30.519898;
print_hex((const unsigned char *)&latitude,8);
double longitude =119.969229;
print_hex((const unsigned char *)&longitude,8);
return 0;
}
|