• Status: Solved
• Priority: Medium
• Security: Public
• Views: 214

# Store Hexadecimal values in a string array

hi experts
I want to store hexadegesimal values in a string array. I use TC3.0

please write a skeletor source code
thansk for all
0
hpyam
1 Solution

Commented:
I'm not sure exactly what you want, so here are a couple of variations:

1) Plop the actual binary in:
char that[123];
unsigned char this;
....
this=0x1b;
strcpy(that,"heres an escape:@");
that[16]=this;

2) Plop the ASCII of the hex:
sprintf(that,"The hex for escape is %02x",this);

Are we close?

0

Commented:
hexa is base 16 = 2^4.
that means you need 4 bits for every digit  ==> 1 byte (char) for every two digits...

long hexa;
char arr[1000];
i=0;

while (hexa>0)
{
arr[i]=hexa%256;  //(two digits)
hexa/=256;       // now extract them
i++;
}

and you have a REVERSE presention...

is this what you do want ?

Yair
0

Author Commented:
I want save hexadecimal values in string array only.
example
I have
Int  a,b;
this values integer I want  values in hexadecimal and save a un string array

example          AF8 store hexadeciamal  value in a string

=)
0

Commented:
even easier:

int num;
char digit;

while (num)
{
digit=num%16;
if (digit<10)
digit+='0';
else
digit+='A'-10;

printf("%c",digit);
// now you have printed an hex num
// in a reverse way...
// but you can do whatever you want
// with the char (adding to an array and more...)
}

to get not reverse it a bit more
difficult - but I am sure you can !

0

Commented:
sprintf (string,"%8X %8X",a,b) ;

as cookre said

if a = 16, b = 15
string = "00000010 0000000F"

0

Commented:
Hi

zulti is very close.
Use

char *string;*temp;
string=malloc(100); //say 100 bytes.
temp=malloc(10);// Small because temporary.

sprintf(temp,"%X",a);
strcpy(string,temp);
sprintf(temp,"%X",b);
strcat(string,temp);

That's it. The string pointer will grow upto 100 bytes.

0

Commented: