By default C promotes short unsigned values to signed int which leads to undefined behaviour when the value is shifted by too much. Force unsigned arithmetic to be perform by explicitly casting to a unsigned type.