"I have no idea why the compiler is treating bit shift output as signed value performing sign extension instead of zero extension." The reason is that unsigned short promotes to signed int unless short and int have the same length. ISO C language standard, section 6.3.1.1. Mr. Lord fixed hdparm but C is unfixable.