0

I am filling a char array 2 bytes at a time. I want to now add an integer that can be up to 4 bytes. Is there an easy way to split this integer into 2, 2 byte chars? For example 2200 into 0x08 and 0x98? Thanks.

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Ancient Dragon
0

copy it to a temp array then copy however you want

unsigned char tmp[sizeof(int)];
int x = 123;
memcpy(tmp,&x, sizeof(int));
// now you can copy tmp array the way you want to
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.