How can I get nth bit value in oracle database?
I am currently using this query:
WITH a AS
(SELECT 7 val
FROM DUAL)
SELECT CASE BITAND (a.val, POWER (2, n-1))
WHEN 0
THEN 0
ELSE 1
END nth_bit
FROM a
Best Answer
The shortest expression you can get is:
where you want to find the
n
th bit ofa
.The shortest query with this expression is:
From what I've read the above expression also works in PL/SQL, eg: