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

How To Serialize DotNet Types into Byte Arrays?

How can I serialize a uint Type into a Byte[4]?
Jul 9 '07 #1
2 1933
Leon,

Serialization has a very specific meaning in .NET, and is different from
what you are trying to do (which was answered in your next post). The
process of serialization in .NET will write a value, but also write type
information as well into the serialization stream, such that predicting the
size of the outcome is tedious, at best. Also, it is not guaranteed that
you will have the same layout in the serialized form as you do in memory.

If you want to truly serialize the contents of the uint into a byte
array, then you would use a BinaryFormatter instance to serialize to a
MemoryStream.

However, what you want to do is use the BitConverter class, as pointed
out in the answers to your next post.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Leon_Amirreza" <am**************@yahoo.comwrote in message
news:uG*************@TK2MSFTNGP06.phx.gbl...
How can I serialize a uint Type into a Byte[4]?


Jul 9 '07 #2
Hi,

Uint value into a Byte[4]:

byte[] bytes = System.BitConverter.GetBytes(<int_or_such_value>);

Other approach is to use BinaryFormatter.Serialize() (but it will be more
then 4 bytes)

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

LHow can I serialize a uint Type into a Byte[4]?
L>
Jul 9 '07 #3

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

Similar topics

2
by: Voronkov Konstantin | last post by:
Thank you for answer, but I still did not got *how* to make serialization of enum type. Can you provide more instructions or hint, please? My task is to serialize enum to something like byte...
1
by: Michael | last post by:
Hi I anyone have a clue or can solve my problem I would be glad :-) Regards Michael I have a problem with creating an XML-document where the returning data from the webservice, have been...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
5
by: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
5
by: Peter | last post by:
I have large arrays or Array type I am planning to Serialize and save the serialized data into Access database as memo field. My question is: Is it safe to save this data in that format, will I be...
18
by: yusuf | last post by:
I basically want to be able to store and retrieve a tree structure in greasemonkey. Unfortunately the GM_setValue and GM_getValue functions only take string key value pairs. Is there a native...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I am using dotnet remoting with a binarry formatter. I have a property that returns a memorystream that has had a file loaded into it. When I try to access this property though I get an...
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...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.