By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,681 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

HELP Please - Convert binary number to string

P: n/a
Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.

Thanks,
Todd

Mar 16 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

<To**********@mentor.comwrote in message news:
Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.
sprintf(sid, "%d", vals2[0]);

make sure sid is big enough to hold the number plus terminating nul. Make
sure vals2 is an array of integers. If val2[0] is double or float use "%f"
instead.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Mar 16 '07 #2

P: n/a
To**********@mentor.com wrote:
Hello,

I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

What do you mean by a "binary number"? Do you mean just an integer,
represented in binary form? Or number that can only take on the values
of 0 and 1?

If the former, what do you want the result to look like? The number in
decimal? The bit pattern? Give an example of input and expected output.


Brian
Mar 16 '07 #3

P: n/a
On Mar 16, 1:27 pm, Todd_Gose...@mentor.com wrote:
>
I've got a problem that I can't fix by myself, I'm fairly new to
programming in C and in Unix and so I'm having a tough time doing a
simple task of converting a binary number to a string. Can anyone help
me with that?

Here is the problem:

vals2 = ldap_get_values(ld,e,b);
if ( vals2 != NULL)
{
strcpy(sid,vals2[0]);
}

The strcpy function isn't working since vals2[0] is a binary number
and not a string. I need to find away to make vals2 a string in order
to copy it to the sid variable.
The term "binary number" could mean any of several things, so you need
to tell us what you mean by it. You also need to tell us the types of
your variables 'vals2' and 'sid', and tell us what format you need the
resulting string to be in (for example "a printable character string
containing the value in decimal" or whatever it is you need).

Mar 17 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.