Operator ~ does not work with unsigned variables.

Just starting out? Need help? Post your questions and find answers here.
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Operator ~ does not work with unsigned variables.

Post by User_Russian »

Operator ~ does not work with unsigned variables.

Code: Select all

a.a = ~2
c.c = ~2
u.u = ~2
User avatar
NicTheQuick
Addict
Addict
Posts: 1227
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Operator ~ does not work with unsigned variables.

Post by NicTheQuick »

The problem is that 2 gets interpreted as integer, then the inverted value is negative and can not be assigned to an unsigned variable. The operation ~2 happens in the compiler itself.
You can change that behaviour when you write the number 2 to 'a' and then do a '~' operation:

Code: Select all

a.a = 2
a = ~a
c.c = 2
c = ~c
u.u = 2
u = ~u

Debug a
Debug c
Debug u
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Post Reply