How to divide an Int into two Bytes in C?
Clash Royale CLAN TAG #URR8PPP How to divide an Int into two Bytes in C? I am working with software embedded in minimal hardware that only supports ANSI C and has minimal versions of the standard IO libraries. I have an Int variable, two bytes in size, but I need to divide it into 2 bytes separately to be able to transmit it, and then I can, reading the two bytes, reassemble the original Int. I can think of some binary division of each byte like this: int valor = 522; // 0000 0010 0000 1010 (entero de 2 bytes) byte superior = byteSuperior(valor); // 0000 0010 byte inferior = byteInferioror(valor); // 0000 1010 ... int valorRestaurado = bytesToInteger(superior, inferior); // 522 but I do not succeed in a simple way of dividing the whole by its weight and it gives me the feeling that it should be trivial (such as with bit shifting) and I do not discover it. Actually, any solution that divides the whole into 2 bytes and reassembles it serves me well. From already thank you very much! ...