Convert PHP pack() function to C#

G

gogaz

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
 
B

Ben Voigt

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));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top