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

Cast de Int32 a byte[]

Hello everybody,

I want to cast an integer of 32 bits in a byte[] id.
How can I break the Int32 id up to set it in the 4 first positions of the
array of byte?
and then, How can I get the full Int32 id of the array of bytes [] ?

In MSDN appears a parse for Int to byte, but not for byte[], and if the
integer of 32 bits has a very long number can take 4bytes up (32bits/8=
4bytes).
Regards.

Jul 21 '05 #1
2 1572
int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Black_angel" <Bl********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
Hello everybody,

I want to cast an integer of 32 bits in a byte[] id.
How can I break the Int32 id up to set it in the 4 first positions of the
array of byte?
and then, How can I get the full Int32 id of the array of bytes [] ?

In MSDN appears a parse for Int to byte, but not for byte[], and if the
integer of 32 bits has a very long number can take 4bytes up (32bits/8=
4bytes).
Regards.


Jul 21 '05 #2
Thank you very much!

"William Stacey [MVP]" wrote:
int t = 14;
byte[] ba = BitConverter.GetBytes(t);
int i = BitConverter.ToInt32(ba, 0);

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Black_angel" <Bl********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
Hello everybody,

I want to cast an integer of 32 bits in a byte[] id.
How can I break the Int32 id up to set it in the 4 first positions of the
array of byte?
and then, How can I get the full Int32 id of the array of bytes [] ?

In MSDN appears a parse for Int to byte, but not for byte[], and if the
integer of 32 bits has a very long number can take 4bytes up (32bits/8=
4bytes).
Regards.


Jul 21 '05 #3

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

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
3
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
7
by: simon | last post by:
I declare variable as int16: int16 hourS; then I open dataReader and set the variable: hourS=rdr.getInt16(1); but I get an error when I start the page:
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
3
by: dbuchanan | last post by:
How do I explicitly cast a string to Byte? Here are my circumstances; The string is from a textbox and could be empty. The Byte is a tinyint in SQL Server 2000 I am using the AddRow method as...
2
by: Black_angel | last post by:
Hello everybody, I want to cast an integer of 32 bits in a byte id. How can I break the Int32 id up to set it in the 4 first positions of the array of byte? and then, How can I get the full...
3
by: PT | last post by:
Hi, not sure if this is just me, an already known bug or what, but if anyone can shed light on why this does what it does it would be greatly appreciated, it seems to work as expected if you're...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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,...
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...

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.