Convert PHP pack() function to C#

  • Thread starter Thread starter gogaz
  • Start date Start date
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
 
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));
 
Back
Top