Re: Binary operators in store procedure?
Posted in 1997
>From: Sten Onbeck <sten.onbeck@sni.se>
>Date: Tue, 11 Feb 1997 10:49:36 +0100
>X-Informix-List-Id: <news.33745>
>
>Is it possible to write something like
>int x
>if ( x & 2) = 2 then
>in a store procedure
Not directly -- SPL is not C (just in case you hadn't noticed:-)
However, I do have a bittest() stored procedure:
-- @(#)bittest.spl 1.1 96/08/26
--
-- bit_test: return the Nth bit of value
CREATE PROCEDURE bit_test(value INT, bit INT) RETURNING INT;
DEFINE i INT;
LET i = 0;
WHILE (i < bit)
IF (value == 0) THEN
EXIT WHILE;
END IF;
LET value = value / 2;
END WHILE;
RETURN MOD(value, 2);
END PROCEDURE;
You could then write:
-- NB: second parameter is the N in 2**N.
if (bit_test(x, 1)) then
...
end if
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>