We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


Arithmetic Bit-shifting — Vertica Forum

Arithmetic Bit-shifting

Jim_KnicelyJim_Knicely - Select Field - Administrator

A fun way to manipulate bits in Vertica SQL is with the use of arithmetic bit-shifting, which moves the bits in a number either left or right and fills in the new values with 0s.

Bit-shifting left is an easy way to multiply by powers of 2, while bit-shifting right divides by powers of 2.

Example:

dbadmin=> SELECT 5 << 2 "5*4=";
5*4=
------
   20
(1 row)

dbadmin=> SELECT 20 >> 2 "20/4=";
20/4=
-------
     5
(1 row)

Helpful Link:
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/LanguageElements/Operators/BitwiseOperators.htm

Have fun!

Sign In or Register to comment.