0x8000U

I have a dumb question…

I understand that “0x8000” means 32,768 shown as a HEX number. What does the “U” mean or do??

The U (or UL or u or ul) tells the compiler to treat the literal value as an unsigned (or unsigned long) value.

Thanks for the info.

Saves you from having to declare the VAR as" Unsigned Char" or "Unsigned int" or what ever

Again thanks

No, it does not.

void setup()
{
  int x = 0x8000U;
  unsigned int y = 0x8000U;
  
  Serial.begin(250000);

  Serial.println(x);
  Serial.println(y);
}

Prints -32768 and 32768 respectively.

OOh!! Did not expect that.. BIG difference

Thanks for the clarification.

It makes sense. It treats the literal it as unsigned, but then you stuffed it into a signed variable and printed that. Try putting the literal in the print.

Serial.println(0x8000U);
Serial.println(0x8000);