Converting hexadecimal to decimal gives unexpected result