Im a newbie and i need help.. would appreciate any help at all...
I need to make a method that accepts a 34 bytes data and inside the method i
need to get the 2nd, 3rd, 4th or any of the byte needed.. Is there an easy
wasy to do this? Ex. i need the 4th byte of the 34 bytes given.. i have no
idea at all how to do this.. please any help would do.. thanks! 6 1179
The classic route would be an array:
public void SomeMethod(byte[] data) {
// paranoia
if(data==null) throw new ArgumentNullException("data");
// even more paranoia (ditch this if overkill)
if(data.Length != 34) throw new ArgumentException("Expected 34
bytes", "data");
// get 4th byte
byte fourth = data[3]; // zero-based
// do something fun
}
Marc
Thanks Marc, i didnt think it would be this simple. My boss told me about
stuff like placing it in a structure so it would be easier and more managed,
if anyone knows about this i would really appreciate it. Thanks marc btw, it
was a great answer.
"Marc Gravell" wrote:
The classic route would be an array:
public void SomeMethod(byte[] data) {
// paranoia
if(data==null) throw new ArgumentNullException("data");
// even more paranoia (ditch this if overkill)
if(data.Length != 34) throw new ArgumentException("Expected 34
bytes", "data");
// get 4th byte
byte fourth = data[3]; // zero-based
// do something fun
}
Marc
Hi Rain,
If your bytes are made up of various data types, feeding it to a struct is
not too hard. Take a look at the article below, and particularly the
"Structs from streams" section.
[Mastering structs in C#] http://www.vsj.co.uk/articles/display.asp?id=501
On Mon, 14 Aug 2006 07:52:01 +0200, Rain <Ra**@discussions.microsoft.com
wrote:
Thanks Marc, i didnt think it would be this simple. My boss told me about
stuff like placing it in a structure so it would be easier and more
managed,
if anyone knows about this i would really appreciate it. Thanks marc
btw, it
was a great answer.
"Marc Gravell" wrote:
>The classic route would be an array:
public void SomeMethod(byte[] data) { // paranoia if(data==null) throw new ArgumentNullException("data"); // even more paranoia (ditch this if overkill) if(data.Length != 34) throw new ArgumentException("Expected 34 bytes", "data"); // get 4th byte byte fourth = data[3]; // zero-based // do something fun }
Marc
--
Happy Coding!
Morten Wennevik [C# MVP]
Byte is byte why need to put into structure? Is you boss asking you to build
a collection like stack, queue and so?
chanmm
"Rain" <Ra**@discussions.microsoft.comwrote in message
news:DB**********************************@microsof t.com...
Thanks Marc, i didnt think it would be this simple. My boss told me about
stuff like placing it in a structure so it would be easier and more
managed,
if anyone knows about this i would really appreciate it. Thanks marc btw,
it
was a great answer.
"Marc Gravell" wrote:
>The classic route would be an array:
public void SomeMethod(byte[] data) { // paranoia if(data==null) throw new ArgumentNullException("data"); // even more paranoia (ditch this if overkill) if(data.Length != 34) throw new ArgumentException("Expected 34 bytes", "data"); // get 4th byte byte fourth = data[3]; // zero-based // do something fun }
Marc
Hi Rain,
See a dentist.
(Sorry, cheesy but I couldn't resist :) :)
--
Dave Sexton
"Rain" <Ra**@discussions.microsoft.comwrote in message news:55**********************************@microsof t.com...
Im a newbie and i need help.. would appreciate any help at all...
I need to make a method that accepts a 34 bytes data and inside the method i
need to get the 2nd, 3rd, 4th or any of the byte needed.. Is there an easy
wasy to do this? Ex. i need the 4th byte of the 34 bytes given.. i have no
idea at all how to do this.. please any help would do.. thanks!
if you put the data into a byte array then you could just access it using an
arrayindex.
byte[] buffer = new byte[2048];
buffer[0] would be the first byte
buffer[1] would be the second byte
....etc
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:OJ**************@TK2MSFTNGP02.phx.gbl...
Hi Rain,
See a dentist.
(Sorry, cheesy but I couldn't resist :) :)
--
Dave Sexton
"Rain" <Ra**@discussions.microsoft.comwrote in message
news:55**********************************@microsof t.com...
>Im a newbie and i need help.. would appreciate any help at all...
I need to make a method that accepts a 34 bytes data and inside the method i need to get the 2nd, 3rd, 4th or any of the byte needed.. Is there an easy wasy to do this? Ex. i need the 4th byte of the 34 bytes given.. i have no idea at all how to do this.. please any help would do.. thanks!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve Mauldin |
last post by:
I came across an example in the MSDN documentation using RC2 encryption(the
link to the article is at the end of this message). When I tried it I had a
problem with getting back the same length...
|
by: Ray Z |
last post by:
So far, I get the idea that if I want to use both the unmanaged and managed
memory, I can not avoid memory copy. But I DO need to avoid it. I get a idea
that maybe I could use "union" to convert...
|
by: Ricardo Quintanilla |
last post by:
i have a code that sends data to a socket listening over as400 platform,
the socket responds to me as a "byte array".
then i need to convert the "byte array" into a string.
the problem is that...
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to...
|
by: rcolby |
last post by:
Evening,
Wondering if someone can point me in the right direction, on how I would
compare a system.guid with a system.byte.
system.guid (pulled from sql server table with a data type of...
|
by: jeremyje |
last post by:
I'm writing some code that will convert a regular string to a byte
for compression and then beable to convert that compressed string back
into original form.
Conceptually I have....
For...
|
by: jackmejia |
last post by:
Hello
I am fighting to sync a C++ client with a C# server, I have managed to create a byte array in C++ stored as char* to be sent over the network to the server written in C#.
on the C# side,...
|
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...
|
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...
|
by: ist |
last post by:
Hi,
I am trying to get (and transfer over ASP.NET) some encrypted data
from some MySQL fields. Since the data contains many unicode
characters, I tried to get the data as a series of ASCII...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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: 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...
|
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: 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,...
| |