The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 bitwise NOT, XOR, NAND ?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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...

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000