473,785 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,vals 2[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 7003

<To**********@m entor.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,vals 2[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**********@me ntor.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...@me ntor.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,vals 2[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
7260
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 another table (on same database) to extract more details. When I get the company name and company no the company no outputs like... 63180001000000000000000000000000 In basic terms I'm only getting it like... $query = "SELECT COMPANYNO FROM...
5
3360
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 printer using a RawPrinterHelper class that i found I believe in the msdn. the class works wonderfully when I send stright text data (in the correctly formated string that the sato printer requires.) but when i go to send a image nothing is...
8
5483
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
11
3541
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 one, please , send VB code for access which I can c/p into one function. It don't have to be RSA, it can be anything which is easy to
2
1507
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 As New IO.StreamWriter(ns) Dim bf As New BinaryFormatter Dim mem As New IO.MemoryStream
1
1331
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 following methods. a. A constructor that creates an integer array of the size specified. b. A method that getArraySize. c. A method that accepts x as integer input parameter (positive or negative). If the number x is positive, converts it to...
7
19233
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 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
8
2745
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 understand why it is doing this. Below is my code, I would be greatfull if someone can guide me through the right path or even help me solve this issue. Problem: The old tool which was written in VB6 works perfect. But I needed to convert this to C#...
12
1637
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 cocatenated characters. For example : I want to convert number 3 using 4 bits, ie 3 <----"0011". After executing, I'm getting this warning: warning: return from incompatible pointer type line:49: warning: function returns address of local variable
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3655
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.