Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Xor in SciLab

714 views
Skip to first unread message

Manoel Campos da Silva Filho

unread,
Mar 27, 2009, 10:12:06 AM3/27/09
to
Hi people. I'm newbie in MatLab and SciLab and I like to know if
exists a exclusive or logical operator in SciLab.
I search in the SciLab manual but I don't found anything. In C
language, the xor operator is ^, but in SciLab, this is
the power operator.

Thanks.

philippe

unread,
Mar 27, 2009, 12:10:24 PM3/27/09
to
Hi manoel,

Manoel Campos da Silva Filho a écrit :


> Hi people. I'm newbie in MatLab and SciLab and I like to know if
> exists a exclusive or logical operator in SciLab.

from a mathematical point of view :

"xor" = "booleans are not equal" = "<>"

we can easily verify this :

-->%t<>%f
ans =

T

-->%t<>%t
ans =

F

-->%f<>%f
ans =

F

-->%f<>%t
ans =

T

Philippe

skouo...@free.fr

unread,
Mar 27, 2009, 3:32:48 PM3/27/09
to
Hi, every body

You should go on the web site of Wikipedia, especially on Wikibooks or
http://fr.wikiwix.com/index.php?lang=en&disp=book or the Scilab own
site.

Wikibooks is fine because, every operator and function are explained.

Good luck!

Sam

Moti Litochevski

unread,
Mar 28, 2009, 3:31:53 PM3/28/09
to
On Mar 27, 5:12 pm, Manoel Campos da Silva Filho

Hi,
This is a small implementation I found somewhere on the web. I
converted the code to Scilab and left all remarks as they are.
Good luck with your learning,
Moti

function y = bitxor(x1, x2)
//BITXOR Bitwise logical XOR operator.
//
// y = bitxor(x1,x2)
// Return the bitwise XOR of x1 and x2. This is the value that has 1
bits
// at positions where x1 and x2, but not both, have 1 bits. Does not
work
// when one of the numbers is negative.
//
// Note that this routine will work only up to 32 bits, or to the
precision
// of your machine's double-precision float representation, whichever
// is smaller.
//
// See also bitand, bitor, any, all, |, &, xor.

// Dave Mellinger
// 27 May 1995

// using a global is slightly faster than recomputing bit_vals every
time (Sun),
// but unfortunately in MATLAB 5.0 you can't tell if globals already
exist.
bit_vals = 2 .^ (0:31);

x1 = pmodulo(floor(x1 ./ bit_vals), 2);
x2 = pmodulo(floor(x2 ./ bit_vals), 2);

y = sum(bit_vals .* pmodulo(x1 + x2, 2));

endfunction

0 new messages