| T O P I C R E V I E W |
| tib |
Posted - 09/06/2006 : 12:47:46 PM Hi, might be a stupid question... but could not find a help nor forum topic... AND & and OR | operators exist in Labtalk. Is there an easy way to realize NOT, XOR and NAND in LabTalk? e.g. bin.(dec) --> bin. (dec.) NOT 1100 (12) --> 0011 (3) 1101 (13) XOR 0100 (4) --> 1011 (11) ... Thanks for hints, Tilman.
|
| 2 L A T E S T R E P L I E S (Newest First) |
| Mike Buess |
Posted - 09/07/2006 : 10:25:46 AM Hi Tilman,
I question your definition of the bitwise NOT (or complement) operator. My C reference uses all 16 bits of unsigned integer to represent a decimal number in bitwise operations. Therefore...
NOT x = 65535 - x x NAND y = NOT (x&y) = 65535 - (x&y) x XOR y = (x|y) & (65535 - (x&y))
In Origin C you can use ^ for XOR by including a pragma in your code. Therefore you can create your own bitwise operators as shown below. Note that bw_xor(x,y) returns the same integer as does my LabTalk XOR expression above.
#pragma xor(push, FALSE)
uint bw_xor(uint x, uint y) { return x^y; }
uint bw_not(uint x) { return 65535 - x; }
uint bw_nand(uint x, uint y) { return 65535 - (x&y); }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 09/07/2006 11:37:11 AM |
| tib |
Posted - 09/07/2006 : 04:28:11 AM Hi, in the meantime I found a possible solution. Key is the NOT function. NOT can be realized in the following way:
NOT z = MOD(2^n-1-z,2^n) where n is the number of digits of the binary number z is the number you want to apply NOT on
with this you can realize NAND:
x NAND y = NOT (x & y)
with this you can realize XOR:
x XOR y = (x OR y) AND NOT(x AND y) = (x | y) & (MOD(2^n-1-(x & y),2^n))
Maybe there is even a shorter way...
|
|
|