473,378 Members | 1,343 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,378 software developers and data experts.

how do you make a string of binary numbers from an array

Hi,
I have an array of numbers, and I need to turn it into a single binary
string. How do I do that?
Thanks
B
Aug 11 '06 #1
5 1873
Bint wrote:
I have an array of numbers, and I need to turn it into a single binary
string. How do I do that?
Sorry, but what you are trying to do?

You could do something like this:

$string = array(1,2,3,5,6,7);
$output = '';
foreach ($string as $ascii)
{
$output .= chr($ascii);
}
Aug 11 '06 #2
Carl Vondrick wrote:
Bint wrote:
> I have an array of numbers, and I need to turn it into a single
binary string. How do I do that?

Sorry, but what you are trying to do?

You could do something like this:

$string = array(1,2,3,5,6,7);
$output = '';
foreach ($string as $ascii)
{
$output .= chr($ascii);
}
Is that ascii and not binary?

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 11 '06 #3
IchBin wrote:
Is that ascii and not binary?
What are you trying to convert to and from?

For example, ascii code --letter.
Aug 11 '06 #4
Rik
Bint wrote:
Hi,
I have an array of numbers, and I need to turn it into a single
binary string. How do I do that?
Thanks
B
Concating the items from decimal to binary?

I'm not really sure how you want to do this, but something like this:

$array = array(7,12,10,2,3);
function concat_dec2bin($v,$w){
$v .= decbin($w);
return $v;
}
$string = array_reduce($array,'concat_dec2bin');

Which will result in 111110010101011 (111 = 7, 1100 = 12,1010 = 10,10 = 2,
11 = 3);

Grtz,
--
Rik Wasmus
Aug 11 '06 #5
Following on from IchBin's message. . .
>Carl Vondrick wrote:
>Bint wrote:
>> I have an array of numbers, and I need to turn it into a single
binary string. How do I do that?

Sorry, but what you are trying to do?

You could do something like this:

$string = array(1,2,3,5,6,7);
$output = '';
foreach ($string as $ascii)
{
$output .= chr($ascii);
}

Is that ascii and not binary?
The OP wants a binary string - That's a bit like asking for a cheese
steak.

Looks like the desperate OP should pay more attention in class and not
come here for their coursework. Better still - If that's the limit of
their intellectual engagement with programming they should think of an
alternative career ... such as say a turnip.
>Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_________________________________________________ _____________
____________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
--
PETER FOX Not the same since the statuette business went bust
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Aug 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: J. Campbell | last post by:
OK...I'm in the process of learning C++. In my old (non-portable) programming days, I made use of binary files a lot...not worrying about endian issues. I'm starting to understand why C++ makes...
4
by: Delali Dzirasa | last post by:
Does anyone know of the fastest way to convert a CString of numbers ie "00000001" to the binary representation in an int? for example CString myVal = "00000001"; int myIntVal = 0; ...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
1
by: Steve Bostedor | last post by:
I'm trying to use the RegistryKey to write a hex number into the registry as a binary type. I know see that in DotNet, the RegistryKey tries to interprate what registry type to create depending...
9
by: Stargate4004 | last post by:
Hi, I have am converting a VB6 application to VB.net and have run into a problem. The application connects to a TCP port on a Linux box and receives a data buffer. The data buffer contains...
2
by: Edvin | last post by:
Why is binary array written to a file different than when converting the binary array to string and then writing it to file! For example: // --- Allocate byte array byte arrByte = new byte;...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
4
by: vcnewbie | last post by:
Hi I'm maintaining a VisualC++ project to increase its security regarding stored passwords. I thought about using SHA256Managed to create a hash for the password when creating a user and when...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.