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

Convert PHP pack() function to C#

P: n/a
Hi,

PHP has a function called pack() (http://us2.php.net/pack). I need to
translate some code that uses this function to C#. What's the C#
equivalent of pack()?

Basically in php

$i = 1038;
pack("N", $i);

it converts string into binary string where first parameter
"N" is to convert it into unsigned long (always 32 bit, big endian byte
order)

I want similar in C#

Thanks

Sep 7 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Sorry, that didn't help at all!!!!

Can you please explain a bit more?

Regards

jo*****@yamagata-europe.com wrote:
http://msdn.microsoft.com/library/de...int32topic.asp

Greets
Joachim
Sep 7 '06 #3

P: n/a
Sorry, I misunderstood the question, I thought you were just looking
for conversions:

Someone else posted your question on this forum:

http://forums.asp.net/thread/1244065.aspx

and he was pointed in this direction:

http://www.codeproject.com/dotnet/Bi...onversions.asp

I haven't seen any classes in .NET doing what pack does - then again
I never really had to do any operations on binary stuff - except for
colours.

Greets,
Joachim

Sep 7 '06 #4

P: n/a
<go***@rediffmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

PHP has a function called pack() (http://us2.php.net/pack). I need to
translate some code that uses this function to C#. What's the C#
equivalent of pack()?

Basically in php

$i = 1038;
pack("N", $i);

it converts string into binary string where first parameter
"N" is to convert it into unsigned long (always 32 bit, big endian byte
order)

I want similar in C#
See System.BitConverter class.

Your example would be: Array.Reverse(BitConverter.GetBytes((Int32)i));
>
Thanks

Sep 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.