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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.