Link to home
Start Free TrialLog in
Avatar of linux_lover2004
linux_lover2004

asked on

data type conversion problem

hello,
                 I am writing program in which i require to have unsigned char * string say (af03d) to be converted to unsigned long int. Which function is avail to me? i am sending that to other program and want that program to recover the unsigned long int to unsigned char * variable.
                 

Avatar of sunnycoder
sunnycoder
Flag of India image

Hi linux_lover2004,

>  Which function is avail to me? i am sending that to other program and
> want that program to recover the unsigned long int to unsigned char * variable.
There is no such function ... You can pass the bit sequence as such, both processes will see the same value and since both are loking for char *, it should appear to be the same to both
A memory address of one process will not be accessible to another process. I hope you know what you are doing.

Cheers!
sunnycoder
Avatar of linux_lover2004
linux_lover2004

ASKER

hello sunnycoder,
            What if i place programs on 2 pcs that mean sending pc program convert to unsigned long int and receiving pc program convert that to unsigned char * then how to pass bit sequence?
try using a void * on the receiving end PC. the void* being a pointer to chunk of memory equalvent to long unsigned int
If both processes see it as a char * and both have same endian-ness, then I see no need for conversion ... In any case conversion is not required unless the data types are of different size ... A simple explicit cast will do ... You need to keep in mind the data size and endian-ness ... bit sequence will be the same as both need to see the same idata and same type
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for my previous example, number can be defined as:
unsigned long int number;
You're going to have to explain in more detail exactly what you want to send.

Do you have some  data in a string that you want to send an have be received as a string?

Do you have the chracter representation of binary data, as hex charcaters 0-9 and A-F?


Do you have some bytes of data that you want to have received as arbitrary data?

Do you have some binary integers or binary real numbers that you want to have received correctly on the other end?

have you used...

sscanf() functions...

use this...

char *ptr the_string = "0xffff";
float f;
int i;
unsigned long ul;

sscanf(the_string, "%0X", &ul);

Regards,
cryptosid


and then to convert it back...

use.. sprintf(the_string,"%0X",ul);

Regards,
cryptosid