#include <stdio.h>

unsigned char a = 0x10;//0001 0000
unsigned char b = 0x20;//0010 0000

int main() {
    unsigned short data = 0;

    data = (unsigned short)(a << 8) + b;//binary: 0001 0000 0000 0000
    //data = data | b;//0x1020 binary: 0001 0000 0010 0000

    printf("data = %x\n", data);

    return 0;
}

#if 0

int main(){
    char a = 0x10;//0001 0000
    char b = 0x20;//0010 0000

    //int c = a;
    int c = (a<<8) + b;//max (a<<31)

    printf("%x\n", c);

    c = (0xff00 & (c<<8)) + (0x00ff & (c>>8));//total space ocupied is 16bits

    printf("%x\n", c);
}

#endif

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: