C/C++ packing signed char into int
- by aaa
hello
I have need to pack four signed bytes into 32-bit integral type.
this is what I came up to:
int byte(char c) { return (unsigned char)c; }
int pack(char c0, char c1, ...) {
return byte(c0) | byte(c1) << 8 | ...;
}
is this a good solution? Is it portable?
is there a ready-made solution, perhaps boost?
Thanks