# "not" operator on an int

**URL:** <https://forum.universal-robots.com/t/not-operator-on-an-int/22829>\
**Category:** URScript\
**Created:** [July 21, 2022, 8:21pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829 "2022-07-21T20:21:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon45313992](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anon45313992](https://forum.universal-robots.com/u/anon45313992)\
**Post date:** [July 21, 2022, 8:21pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829/1 "2022-07-21T20:21:46Z")

</div>

Hello,

I have a simple question but can’t find the answer to in the documentation.

Let’s say we receive an int with socket\_read\_binary\_integer() and that int represents a “keep alive” signal.

So value would only be 0 or 1.

Can I use the “not” operator to set a variable to the opposite value of “keepalive” ?

Thank you !

---

<div class="post-metadata">

**Author:** ![anon34306213](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon34306213](https://forum.universal-robots.com/u/anon34306213)\
**Post date:** [July 25, 2022, 1:19pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829/2 "2022-07-25T13:19:02Z")

</div>

Usually a “NOT” operation would not be allowed for Integers, especially since the behaviour that you are describing is the behaviour of a “NOT” operation **only** fo booleans.

Here is a specific example:  
Considering a boolean that is represented by 1 bit: using a NOT operation when 0 would return 1 and viceversa  
However, an integer has 32 bits: using a NOT operation when 0 would return 2,147,483,647 and viceversa

Now about possible solutions:

- Either use a cast, to reduce the datatype of the int to a bool (which i don’t even know if it is supported honestly)

- Or, only if you are **sure** that the value of that variable is always either 0 or 1, you can use some very simple conversion function.

For example:  
var = -var + 1

which converts 0 to 1 (-0 + 1) and 1 to 0 (-1 + 1).

Hope it helps

---

<div class="post-metadata">

**Author:** ![anon45313992](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anon45313992](https://forum.universal-robots.com/u/anon45313992)\
**Post date:** [July 25, 2022, 1:36pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829/3 "2022-07-25T13:36:51Z")

</div>

Thanks, I went with a manual conversion

---

<div class="post-metadata">

**Author:** ![SynchMaster](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@SynchMaster](https://forum.universal-robots.com/u/SynchMaster)\
**Post date:** [July 25, 2022, 1:49pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829/4 "2022-07-25T13:49:29Z")

</div>

What about a if statement?

if (var == 0){  
var = 1  
}else if (var \> 0){  
var = 0  
}

---

<div class="post-metadata">

**Author:** ![anon45313992](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anon45313992](https://forum.universal-robots.com/u/anon45313992)\
**Post date:** [July 25, 2022, 2:04pm UTC](https://forum.universal-robots.com/t/not-operator-on-an-int/22829/5 "2022-07-25T14:04:48Z")

</div>

Yes, that’s pretty much what I’ve done
