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

Data conversion

Roy
In C#, how do I convert a data (could be any primitive types or user defined
structures such as int, short [] ...) to byte[]? How do I convert it back
assume I know the type in advance?
Mar 3 '06 #1
1 1369
You may be able to cast primitive types :

int i =4;
byte b= (byte)i;

However, structs etc. you will most likely need to use the BinaryFormatter
class to convert a type to a byte array, and back.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Roy" wrote:
In C#, how do I convert a data (could be any primitive types or user defined
structures such as int, short [] ...) to byte[]? How do I convert it back
assume I know the type in advance?

Mar 3 '06 #2

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

Similar topics

12
by: Dillon Mantle | last post by:
HI All Does any one know how to convert a binary file into a readable (by human) file? Its from a bin file, has addresses and stuff which I can work out... but how do you do the actual...
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
6
by: New MSSQL DBA | last post by:
Hi all, we are now planning to upgrade our application from a non-unicode version to a unicode version. The application's backend is a SQL Server 2000 SP3. The concern is, existing business...
4
by: Ivan | last post by:
I am running a statically bound COBOL program on DB2 7.1 OS/390 trying to insert EBCDIC strings into a varchar column in a table on DB2 UDB 7.2 FP10a Workgroup edition. The varchar column is...
4
by: wb | last post by:
Newbie at .net having trouble with data conversion. I am using the random constructor and trying to pass in seed value of time as instructed by help. rvalue = new random(int) dim x as long...
1
by: tony.fountaine | last post by:
I am working on a project to read a Bosch Measurement Data File (MDF). The file contains a number of blocks that can be read from the file using a baisc structure. For example the ID BLOCK is as...
0
by: bpo_ccs | last post by:
We are into BPO and Software development business for past six and half years. We are looking for the following any kind of business from your end. Back Office Process Data Entry, Large Volume...
4
by: alacrite | last post by:
I have a class that I want to turn its contents into csv file. I want to be able to set the value of the delimiter, the name of the file it gets saved to, the path of that file, and maybe a few...
23
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.