Example: 1011 + 1001 = 10111001

UPD: wrong with an example, of course, like this 00001011 + 00001001 = 0000101100001001

    2 answers 2

    unsigned char a = …; unsigned char b = …; unsigned int result = (a << 8) | b; 
    • 3
      in the falstaf answer, "bytes" are added, that is, 2x 8 bits and @worialhat in the example, half bytes are added, that is, 2x 4 bits unsigned char a = 11; // 1011 unsigned char b = 9; // 1001 unsigned int result = (a << 4) | b; - ProkletyiPirat
    • 2
      The example in question, of course, does not correspond to the title. One can only guess what exactly the vehicle wants to know. Interestingly, and such an example 1010000 + 100 = 1010000100 also fits the concept of "sticking two bytes"? - avp
    • yes, I was wrong, just as you said and wanted to do, but changed my mind and the first answer suits me perfectly - worialhat
      unsigned char a = ...; unsigned char b = ...; unsigned short c = ((unsigned short)a << 8) | b;