• C

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
hpyamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cookreCommented:
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
yairyCommented:
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
hpyamAuthor 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
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

yairyCommented:
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
zultiCommented:
sprintf (string,"%8X %8X",a,b) ;

as cookre said

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

0
sumant032199Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sumant032199Commented:
Thank you for your assessment.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.