469,648 Members | 1,170 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

Convert PHP pack() function to C#

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
4 8664
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
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
<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.

Similar topics

3 posts views Thread by Karunakararao | last post: by
4 posts views Thread by Karunakararao | last post: by
2 posts views Thread by Brian | last post: by
2 posts views Thread by mb2812 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.