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

memcpy like function in c#

i have a byte array
e.g.
byte[] abc = new byte[100];

and i have some integers
e.g.
int height = 166;
int age = 23;

i wanna store them into the byte array abc like "[height 4-byte][age
4-byte]"
i.e.
memcpy(&abc[0], &height, sizeof(height));
memcpy(&abc[4], &age, sizeof(age));
and reverse
memcpy(&height, &abc[0], sizeof(height));
memcpy(&age, &abc[4], sizeof(age));

how should i do it in C#?

thx!
Nov 15 '05 #1
1 3462
o..i just found this

BitConverter.GetBytes(age).CopyTo(abc, 3);
"babylon" <am***@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...
i have a byte array
e.g.
byte[] abc = new byte[100];

and i have some integers
e.g.
int height = 166;
int age = 23;

i wanna store them into the byte array abc like "[height 4-byte][age
4-byte]"
i.e.
memcpy(&abc[0], &height, sizeof(height));
memcpy(&abc[4], &age, sizeof(age));
and reverse
memcpy(&height, &abc[0], sizeof(height));
memcpy(&age, &abc[4], sizeof(age));

how should i do it in C#?

thx!

Nov 15 '05 #2

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

Similar topics

13
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard...
35
by: Christopher Benson-Manica | last post by:
(if this is a FAQ or in K&R2, I didn't find it) What parameters (if any) may be 0 or NULL? IOW, which of the following statements are guaranteed to produce well-defined behavior? char src;...
7
by: Richard Hayden | last post by:
Hi, I've just upgraded my gcc and I'm currently trying to compile some code for my own operating system kernel, but I am getting an error of "Undefined reference to `memcpy`" when I try to link...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
11
by: Peter Pichler | last post by:
A colleague encountered an interesting problem. Suppose we have a C function like this: void WRITE_THING(void* addr, THING t) { memcpy(addr, &t, sizeof t); } to copy a THING to any byte...
1
by: remove the CAPS | last post by:
Hi, all. This question came up in a code review: are null pointers legal as arguments to memcpy? That is, is the program at the end of this article strictly conforming? (Of course, I check the...
0
by: Michael | last post by:
Hi developers. I´m trying to migrate a C++ sample from the Canon SDK Version 7.1 into C#. I have come across lots of pit falls (and luckily solved them) but now I´m stuck with some of the nice...
6
by: novice | last post by:
Please explain with an example whts the DIFFERENCE between "memcpy" and "memmove"
18
by: Mark | last post by:
Hi List, I want to write a function to copy some data out of a hardware buffer. The hardware can change the contents of this buffer without it being written to by my function. I want to use...
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
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: 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
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
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 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.