473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

HELP Please - Convert binary number to string

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
3 6976

<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Darren | last post by:
Hi wondering if anyone can help. What i'm trying to do is get a company from a MSSQL database with the COMPANYNO which is a 'uniqueidentifier'. Then with this COMPANYNO I want to reference it to...
5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
11
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any...
2
by: Tiraman :-\) | last post by:
Hi Everyone, i have the following problem in my client-server Application My server take array and serialize it into the memorystream Dim ns As NetworkStream = client.GetStream() Dim writer...
1
by: al mwaj3 | last post by:
please I need help in this problem, I must send it tomorrow the problem is (1) Write a Java class called: Binary that has two data fields: an integer array, and an integer size as well as the...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
8
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't...
12
by: Nezhate | last post by:
Hi There, I'm writing a program that takes a decimal number and returns it's binary equivalent. the problem is that I don't know how to return (from function) the binary value as an array of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.