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

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 9265
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mich | last post by:
I'm going crazy trying to convert an Access Function to SQL. From what I've read, it has to be done as a stored procedure. I'm trying to take a field that is "minutes.seconds" and convert it to...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
3
by: Karunakararao | last post by:
Hi All I done this function VB.NET i want convert this function in C# pls help me. Sub CustomPager(ByVal STCPagerGrid As Object) Dim intCtr As Integer Static intLastItem As Integer
4
by: Karunakararao | last post by:
Hi all Please Convert the VB.Net to C# .NET Sub CustomPager(ByVal STCPagerGrid As Object) Dim intCtr As Integer Static intLastItem As Integer Static intCount As Integer Static intTotalPage,...
5
by: scottrm | last post by:
I have a asp.net web service built in c# which is accepting a string parameter from a vb6 client. The string parameter contains some xml. I am attempting to convert the string to a byte array using...
2
by: Brian | last post by:
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()? Thanks, Brian Example code...
2
by: mb2812 | last post by:
I'm getting the T_STRING error ("Parse error: syntax error, unexpected T_STRING in alexa5.php on line 26") when using the pack function: function calculate_RFC2104HMAC ($data, $key) { return...
0
by: setheo | last post by:
To all gurus, I am currently converting some of C++ codes to VB.net The C++ Codes is as follows : ================= C++ CODE ================== typedef struct _tagBBCameraParameter {...
3
dlite922
by: dlite922 | last post by:
I'm building a monospaced text output and it works fine with pack("A23",$variable) for example that makes sure the variable valuse takes up 23 spaces. If the string is less than 23, it fills the rest...
3
by: prelude | last post by:
I'm looking into how the Python's pack function is implemented. Does anyone know where the source is located? I grep the entire lib folder but couldn't find it. I have the unfortunate task of...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.