0
select utl_raw.bit_or('32','3') from dual;

Result : 33

I'd like to know how to get similar output in postgresql. Please help.

user1720827
  • 137
  • 1
  • 3
  • 15

2 Answers2

2

utl_raw.bit() apparently uses hex values.

Postgres supports bit operations only on bit strings which means those hex input values need to be converted to a bit string, then you can use the built-in functions.

Based on Erwin's answer to convert hex to bit, you can do this:

select (x'32'::bit(8) | x'03'::bit(8));

This returns

00110011

Note the leading 0 for the second value. x'3'::bit(8) will return 00110000 but with a leading 0 the conversion to a bit string results in 00000011. See the linked answer for more details on that.

To get a hex number back, we must first convert it into an integer, then we can use to_hex() on it:

select to_hex((x'32'::bit(8) | x'03'::bit(8))::int)

returns 33

0

There is no builtin function for that.

It should not be too hard to write that in the procedural language of your choice. For PL/pgSQL you could use the get_byte() and set_byte() functions.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263