c++ - Function that copies into byte vector reverses values -
hey, i've written function copy variable type byte vector, whenever insert gets inserted in reverse.
here's code.
template <class type> void packet::copytobyte(type input, vector<uint8_t>&output) { copy((uint8_t*) &input, ((uint8_t*) &input) + sizeof(type), back_inserter(output)); }
now whenever add example uint16_t value 0x2f1f gets inserted 1f 2f instead of expected 2f 1f.
what doing wrong here ?
regards, xeross
if on little-endian machine (e.g., x86), bytes appear reversed (i.e., lower order bytes appear before higher order bytes).
if want reverse order of bytes, can use std::reverse
.
Comments
Post a Comment