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

Put some bytes into a structure?

Dan
Is there a way to place x number of bytes directly into a
structure? Specifically with this structure:

Private Structure HeaderVersion1
Dim intVersion As Int16
Dim intCount As Int16
Dim intSysUptime As Int32
Dim intUnix_Secs As Int32
Dim intUnix_nsecs As Int32
End Structure

Is there an efficient way to read the first 16 bytes from
a byte array into the structure so that the first 2 bytes
= intVersion, the second 2 = int Count, the next 4 =
intSysUptime, etc. Thanks for your input.

Dan
Nov 20 '05 #1
3 945
> Is there a way to place x number of bytes directly into a
structure?


Use some bytes shifting and/or masking with AND, >>, << operators.
Read
http://msdn.microsoft.com/library/en...changesanchor6
article on MSDN, read "Breaking Apart a Multipart Value" part.

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
Nov 20 '05 #2
* "Dan" <an*******@discussions.microsoft.com> scripsit:
Is there a way to place x number of bytes directly into a
structure? Specifically with this structure:

Private Structure HeaderVersion1
Dim intVersion As Int16
Dim intCount As Int16
Dim intSysUptime As Int32
Dim intUnix_Secs As Int32
Dim intUnix_nsecs As Int32
End Structure

Is there an efficient way to read the first 16 bytes from
a byte array into the structure so that the first 2 bytes
= intVersion, the second 2 = int Count, the next 4 =
intSysUptime, etc. Thanks for your input.


If you have a pointer to the data, you can use
'System.Runtime.InteropServices.Marshal.PtrToStruc ture'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Dan
Got it thanks!
Nov 20 '05 #4

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

Similar topics

19
by: becte | last post by:
I need to use three bytes to store four 6-bit integers (4 * 6 = 3 * 8) like this 11111122|22223333|33444444 Suppose the input is, int c1, c2, c3, c4, range 0 .. 2^6 -1 and the output is int...
5
by: Kobu | last post by:
In embedded systems (programmed in C), often times structure declarations are used to group together several status/control/data registers of external hardware (or even internal registers). The...
8
by: Ken Dopierala Jr. | last post by:
Hi, I'm reading the header file of a PCX image and I need to convert 2 bytes to a short. How would I go about doing this? I know that they are bytes 8 & 9 in my byte array. I'm not sure how to...
2
by: manochavishal | last post by:
Hi, In standard i have come across: 6.2.6 Representations of types 6.2.6.1 General 6.When a value is stored in an object of structure or union type, including in a member object, the...
1
by: spamacon | last post by:
Hello, I have a strange situation using .Net FW 1.1. I want to use Marshal.PtrToStructure to fill the structure below. The first 3 fields get filled correctly: ulStruct describes how big the...
14
by: Francine.Neary | last post by:
Consider the following situation. I have a large static array s of structs, say of size 500. I also need a smaller array of chars, say of size 100, which has nothing to do with the struct. To...
8
by: sexauthor | last post by:
I'm converting a VB6 application over that called a 3rd party DLL with specific data structures. The VB6 code defined custom types for those data structures (ie: one with the specific data types,...
6
by: ssubbarayan | last post by:
Dear all, I developed the following program: void parsebytes(unsigned char* data); struct info { unsigned char day; unsigned char month; short year;
8
by: Sam T | last post by:
Thanks for at least reading this. Quick overview: I am new to object oriented programming (go FORTRAN) and have jumped into developing a C#.NET application that allows a user to input some values in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.