473,401 Members | 2,146 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,401 software developers and data experts.

ulong to byte[]

How can a UInt64 be converted to a byte[] ????
Nov 15 '05 #1
2 6586
Nadav <No*@today.com> wrote:
How can a UInt64 be converted to a byte[] ????


See BitConverter.GetBytes(ulong).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
On Sun, 4 Jan 2004 16:50:16 -0000, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
Nadav <No*@today.com> wrote:
How can a UInt64 be converted to a byte[] ????


See BitConverter.GetBytes(ulong).


And if speed is a factor:
unsafe static byte[] GetBytes(UInt64 value)
{
byte[] bytes = new byte[8];
fixed(byte* b = bytes)
*((UInt64*)b) = value;
return bytes;
}
The BitConverter version has a couple layers of indirection, so its
about 3 times slower (GetBytes(value)>GetUInt64Bytes(value)>internal
runtime call). It's strange, they sometimes do internal calls (for
Integral types) and sometimes they write their own (for floating-point
types).

Austin
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: alex | last post by:
how do i initialize an atl ULONG* variable? ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World!...
3
by: Francois St-Arnaud | last post by:
Hello All, I have the following property in a C# class in a .NET 2003 project: public const ulong MASK_1 = 0x8000000000000000; I find the following observations unsettling (from my Command...
3
by: Curt Krueger | last post by:
I'll spare you the details of why we need this, but what I'm needing to do is convert -9999 to a positive ulong value. Any code examples or ideas on how to do this, where to look? thanks, Curt
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
9
by: Sanjib Biswas | last post by:
Could anyone point out to me the difference between ulong (C#) and UInt64/ULong (VB.Net)? I was under the impression that both are same. Below C# code works fine for a particular value of 'data'...
12
by: AK_TIREDOFSPAM | last post by:
I need to store a uint in an array of bytes. Doing it old fashioned style works: byte b=new byte; ulong ul = 1; for(int j=0; j<8; j++) { --- obviously I could (and did) optimize the code...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.