?
Solved

data type conversion problem

Posted on 2005-04-26
9
Medium Priority
?
324 Views
Last Modified: 2010-04-15
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.
                 

0
Comment
Question by:linux_lover2004
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13865641
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
0
 

Author Comment

by:linux_lover2004
ID: 13865716
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?
0
 
LVL 4

Expert Comment

by:furqanchandio
ID: 13865744
try using a void * on the receiving end PC. the void* being a pointer to chunk of memory equalvent to long unsigned int
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:sunnycoder
ID: 13865940
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
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 13866136
since string appear to be an hex number, you can convert to a integer easily with sscanf

int number;
sscanf(yourstring, "%x", &number);

if you want to convert to a string again, use sprintf;

char somebuf[10];
sprintf(somebuf, "%x", number);

Of course, this will work if both PC are the same type (by example 2 intel compatible machines, no matters operating system)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13866159
for my previous example, number can be defined as:
unsigned long int number;
0
 
LVL 22

Expert Comment

by:grg99
ID: 13866590
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?

0
 
LVL 5

Expert Comment

by:cryptosid
ID: 13883585
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


0
 
LVL 5

Expert Comment

by:cryptosid
ID: 13883588
and then to convert it back...

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

Regards,
cryptosid
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question