Sample Header Ad - 728x90

How to format a fixed-length number as a binary string?

1 vote
1 answer
1140 views
I'm trying to wrap my head around how Postgres represents numbers as binary. How would I format a fixed-length number as a string of ones and zeroes? Example:
select fmt((1<<0)::int2); -- something like 0000 0000 0000 0001
select fmt((1<<2)::int2); -- something like 0000 0000 0000 0100
EDIT: I'm working on postgres 14.
Asked by Steven Kalt (73 rep)
Oct 1, 2022, 09:40 PM
Last activity: Oct 2, 2022, 11:13 PM