RosettaCodeData/Task/Twos-complement/M2000-Interpreter/twos-complement.m2000

13 lines
363 B
Plaintext

Module Complement2{
// we use binary.and to get a number in range of byte 0 to 255
byte k, v
v=random(1, 255) ' there is no two's complement for zero
z=binary.and(binary.not(v)+1, 0xFF)
print v
print z
print z=255-v+1 // z is type of byte always positive
print sint(z+0xFFFFFF00)=-v // using 4bytes, we add unsinged 0xFFFFFF00
}
Complement2
Complement2