This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bit operation

Hello. I use nRF52 , PCA10040 , S132 , SDK 11 & Keil5.

I want nrf to do bit operation. The code about bit operation is following.

unsigned char tmp[2]; unsigned short us; tmp[0] = 0xf8; tmp[1] = 0x59; us = (tmp[0] << 8) | tmp[1]; printf("%d\r\n",us);

I thought the printf("%d\r\n",us); should output 63577, but it output another number. What is my code wrong?

Please help me.

Thanks,

Parents
  • BTW. I was referring to gcc a toolchain rather than the compiler (perhaps I should have made this explicit)

    I don't have time to try all the different gcc libs, I suspect they all behave the same

    But as a matter of interest, I compiled the code in Visual Studio, targeted for Win32 and it also works fine.

    I don't have any other 32 bit compilers, but perhaps someone else has IAR and can confirm the behavior under that toolchain

    Perhaps the OP can try the different libs in Keil

Reply
  • BTW. I was referring to gcc a toolchain rather than the compiler (perhaps I should have made this explicit)

    I don't have time to try all the different gcc libs, I suspect they all behave the same

    But as a matter of interest, I compiled the code in Visual Studio, targeted for Win32 and it also works fine.

    I don't have any other 32 bit compilers, but perhaps someone else has IAR and can confirm the behavior under that toolchain

    Perhaps the OP can try the different libs in Keil

Children
No Data
Related