So, the other day, I was working in Unity, and trying to find the complement of a byte number. That is, 255 - myByte. So, I write this :
Byte newByte = 255 - myByte;
And it says that it can't convert from a byte to an int. Okay... So, I do this:
Byte newByte = byte.MaxValue - myByte;

And still, it errors the same thing. So, a quick google search proves that no matter what, the subtraction operator returns an int. WHAT IS WRONG WITH C#? That is the dumbest thing ever!

  • 0
    Wait so.... 3.0 - 1.1 will give me 2?

    So to handle floating point you, uh, i guess use modulus and multiplication and do like

    30 - 11 = 19

    Then convert to float then divide by 10.

    Or ... gah.
  • 0
    Probably you're missing a cast
  • 1
    @Jormungandr I originally tried casting. I did (byte)255 - myByte; and it still didn't work. The working solution was: newByte = (byte)(byte.MaxValue - myByte)
  • 0
    @SpencerBeige Yeah, this happens cause byte is an unsigned int, and not int. So you must cast.
Add Comment