function returns unexpected number

Hello,
I try to build 32bit value given by putting together 4 bytes: 0x18,0xE7,(uint8_t)c, (uint8_t)~c
What is wrong? I got: 18E68877, expected: 18E78877

// this function prints wrong value
static void put_ir_code_1( uint8_t c)
{
  uint32_t nn;

  nn = 0x18E70000;
  nn += ((c) << 8);
  nn += (uint8_t)(~c); // lsb
  Serial.println(nn, HEX); // RS232 returns: 18E68877, expected: 18E78877
}

// this function returns proper value
static void put_ir_code_2( uint8_t c)
{
  uint32_t nn;

  nn = 0x18E78877;
  Serial.println(nn, HEX); // RS232 returns: 18E78877
}

void setup() {
  uint8_t i;
  Serial.begin(9600); // send and receive at 9600 baud
  i = 0x88;
  put_ir_code_1(i);
  put_ir_code_2(i);
}

void loop() {
  // put your main code here, to run repeatedly:

}

try

  nn |= (c << 8);
  nn |= (~c); // lsb

You are running into integer promotion to a signed integer. Google C++ integer promotion for the details of what happens when a byte value is bitshifted like you do with c<<8.

If you want an unsigned result, you must cast specifically.

static void put_ir_code_1( uint8_t c)
{
  uint32_t nn;

  nn = 0x18E70000;
  //nn += ((c) << 8);
  nn += ((uint16_t)c <<8);
  nn += (uint8_t)(~c); // lsb
  Serial.println(nn, HEX); // RS232 returns: 18E68877, expected: 18E78877
}

Try

static void put_ir_code_1( uint8_t c)
{
  uint32_t nn;

  nn = 0x18E70000;
  nn |= (c << 8) & 0xFF00;
  nn |= ~c & 0xFF;
  // or, same result:
  //nn |= (uint16_t)c << 8;
  //nn |= (uint8_t)~c;
  Serial.println(nn, HEX); // RS232 returns: 18E68877, expected: 18E78877
}