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
| int main (void)
{
//char ref[]="7B14AE47E17A943F";
char base_bin[]="0111101100010100101011100100011111100001011110101001010000111111"; // ram
char hex[]="\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,\0,";
int x=0;
int y=0;
int z=1;
int pos=3;
int i;
unsigned int d1=0;
char c;
while ( pos < 64) {
for (i=pos; i > pos-4; i--)
{
if ( base_bin[i] == '1' ) {
d1=d1+(unsigned int)pow(2,y);
}
y++;
if ( y > 3 ) {
y=0;
if (d1>=0 && d1<=9) c = (char)(d1+48);
else if (d1>=10 && d1<=15) c = (char)(d1+55);
hex[z-1]=c;
z++;
y=0;
x++;
d1 = 0;
}
}
pos=pos+4;
}
cout << "Hex string = " << hex << endl;
return 0;
} |
Partager