1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
// test_1
#include <stdio.h>
#include <stdlib.h>
typedef unsigned char byte;
int main()
{
//unsigned int number = 0xADFE;
int number = 0xADFE;
int temp;
char join[4] = {0,0,0,0};
byte ab = (byte) (number >> 8);
byte cd = ((byte) number);
byte ab_hi =(0xF0 & ab)>>4;
byte ab_lo = 0x0F & ab;
byte cd_hi =(0xF0 & cd)>>4;
byte cd_lo = 0x0F & cd;
printf("\n\n Int Number...: %X", number);
printf("\n\n u Char ab....: %X", ab);
printf("\n\n u Char cd....: %X", cd);
printf("\n\n u Char ab_hi.: %X", ab_hi);
printf("\n\n u Char ab_lo.: %X", ab_lo);
printf("\n\n u Char cd_hi.: %X", cd_hi);
printf("\n\n u Char cd_lo.: %X", cd_lo);
// Store unsigned char in string vector Char Join
join[0] = ab_hi;
join[1] = ab_lo;
join[2] = cd_hi;
join[3] = cd_lo;
printf("\n\n Char Join....: ");
for(int i = 0; i < 4; i++)
{
printf("%X", join[i]);
}
// String vector Char Join to int
// char join[4] = {'A','D','F','E'};
sscanf(join, "%x", &temp);
printf("\n\n Int Temp.....: %d",temp );
printf("\n\n");
return 0;
}
|