Irobot Roomba Movement Panel icon Irobot Roomba Movement Panel — Control Roomba/Create via ARC: drive, stream sensors, read encoders, configure COM/HW UART, and send pose to NMS for mapping/navigation. Try it →
Asked — Edited
1 Participant
two's complement

Two's Complement

Hi, I need to do "two's complement" on numbers but can't seem to find any commands in the software that would let me do that in any easy way.  Am I over looking a command?  


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

Author Avatar
PRO
USA
#1  

Add the Javascript plugin and use Javascript example:

function TwosComplement8Bit(dec)
{
  return ((dec >>> 0) & 0xff);   
}
 
EZB.SetVar("$neg128", TwosComplement8Bit(-128));
EZB.SetVar("$neg127", TwosComplement8Bit(-127));
EZB.SetVar("$neg64", TwosComplement8Bit(-64));
EZB.SetVar("$neg1", TwosComplement8Bit(-1));

Run the script, then you can confirm the above EZ-Scripts variables:

User-inserted image

#2  

Hi ptp, thanks for taking the time to answer my question.

Al