This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Unsigned char won't hold a value of decimal 128 or more

Hi

I'm a new programmer; I'm having problems with unsigned char. I assign a decimal value of 128 to an unsigned char but when I printf this variable comes out as -128. If I assign 127 it comes out at +127, if I assign 129 it comes out as -129. Even if I assign a value of 127, then add 1 it still comes out as -128.

It's definitely an unsigned character but it seems to be acting like a signed char.

unsigned char EncVal8;

if(Pin8 == 1)
  {
  EncVal8 = 128;          /*If Pin 8 is on then the Position Value for this Pin will equal  128 */
  }

Help me please….

Cheers

Stewart

Parents Reply Children
No data