473,750 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9324
Sorry, that didn't help at all!!!!

Can you please explain a bit more?

Regards

jo*****@yamagat a-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***@rediffma il.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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.BitConve rter class.

Your example would be: Array.Reverse(B itConverter.Get Bytes((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
5015
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 minutes. This is what I have in Access: Function ConvertToTime (myAnswer As Variant) Dim myMinutes myMinutes-(((((myAnswer * 100)Mod 100/100/0.6)+(CInt(myAnswer-0.4)))) ConvertToTime =(myMinutes)
4
9269
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 a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
3
2313
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
1548
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, lintCurrentPage As Integer
5
9213
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 the Convert.FromBase64String function but get the following error. Invalid length for a Base-64 char array The same code works ok if I call it from an asp.net client. In that client I am just passing the parameter through as a standard...
2
727
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 using pack():
2
2227
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 base64_encode ( pack ( "H*" , sha1((str_pad($key, 64 , chr ( 0 x00)) ( str_repeat ( chr ( 0 x5c), 64 ))) . pack ( "H*" , sha1((str_pad($key, 64 , chr ( 0 x00)) ( str_repeat ( chr ( 0 x36), 64 ))) . $data))))
0
1371
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 { unsigned int preview_width;
3
1802
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 with spaces. BUT now i have dollar amount which of course want to align right (pad the spaces on the left) any ideas?
3
2867
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 converting some python code which uses pack extensively into C++ :(
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8257
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.