Whether there is an alternative of shift
operators in PL/SQL? There is bitand
function, but it accepts only binary_integer-type arguments.
What should I do if I need check up lower/higher bit of really long number (probably set in the line)?
In C
there are <<
and >>
operators. How I can realise them in PL/SQL?
The bitwise shift operators are the right-shift operator ( >> ), which moves the bits of an integer or enumeration type expression to the right, and the left-shift operator ( << ), which moves the bits to the left.
The <> syntax is for naming loops. Useful when you have nested loops and need to use the EXIT loop_name WHEN ... syntax to control which loop to exit.
The left shift operator ( << ) shifts the first operand the specified number of bits, modulo 32, to the left. Excess bits shifted off to the left are discarded.
The following answer is not endianness agnostic and my wording is based on little endian format...
You can shift bits simply multiplying (shift left) or dividing (shift right) the argument by 2 to the power of x where x is the number of bits to shift. for example, if I need to shift the low-order byte of a number (255:11111111) 16 bits to the left I would perform the following operation:
select 255 * power(2,16) from dual;
-- the result will be (16711680:111111110000000000000000)
conversely, if I want to shift the value 16711680 16 bits to the right I would perform the following:
select 16711680 / power(2,16) from dual;
-- the result will be (255:11111111)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With