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

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
Asked:
hpyam
1 Solution
 
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
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

 
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
 
sumant032199Commented:
Thank you for your assessment.
0

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now