Byte to Char

I'm sending a byte on a C# side (over a serial port) over to the arduino. I want the arduino to read that byte and then put that value into a char variable. My question is, if the value is greater than 127/128 will it be positive and if it's less than that, will it be negative in the new char?

Example:

If I read a byte (value = 255) and I put that value into a character, will it be 127 and if I have another byte (value = 0) will that value become -128? Thank you very much for the help.

Mattix:
I want the arduino to read that byte and then put that value into a char variable.

if ( Serial.available() )
{
  char ch;
  ch = Serial.read();
}

Got it.

My question is, if the value is greater than 127 /128 will it be positive

No. An unsigned eight bit value greater than 127 is interpreted as a negative signed value.

and if it's less than that {128}, will it be negative in the new char?

No. An unsigned eight bit value less than or equal to 127 is interpreted as a positive signed value.

If I read a byte (value = 255) and I put that value into a character, will it be 127

No. An unsigned eight bit value of 255 when converted to a signed value is interpreted as a -1.

and if I have another byte (value = 0) will that value become -128?

No. Zero is zero.

Maybe this will help...

Uns Hex Sig


0 0x00 0
1 0x01 +1
2 0x02 +2
... ... ...
126 0x7E +126
127 0x7F +127
128 0x80 -128
129 0x81 -127
130 0x82 -126
... ... ...
254 0xFE -2
255 0xFF -1

Ok thank you very much. I think I can use the map function to solve my problem. Have a good day!

Also, I understood hex, just kind of confused what would happen going from signed to unsigned. You cleared that up.

Mattix:
Ok thank you very much.

You are welcome.

I think I can use the map function to solve my problem.

If you describe the problem I suspect someone here can offer a simpler solution.

Have a good day!

You too!

It's nothing too bad. I don't think I'll have further difficulties, but if I do, I'll post here in a few minutes.