0000000000000001 | 0000000000000000 | 0000000000000010
(16 rows)
+SELECT b, b >> 8 AS bsr8, b << 8 AS bsl8
+ FROM BIT_SHIFT_TABLE ;
+ b | bsr8 | bsl8
+------------------+------------------+------------------
+ 1101100000000000 | 0000000011011000 | 0000000000000000
+ 0110110000000000 | 0000000001101100 | 0000000000000000
+ 0011011000000000 | 0000000000110110 | 0000000000000000
+ 0001101100000000 | 0000000000011011 | 0000000000000000
+ 0000110110000000 | 0000000000001101 | 1000000000000000
+ 0000011011000000 | 0000000000000110 | 1100000000000000
+ 0000001101100000 | 0000000000000011 | 0110000000000000
+ 0000000110110000 | 0000000000000001 | 1011000000000000
+ 0000000011011000 | 0000000000000000 | 1101100000000000
+ 0000000001101100 | 0000000000000000 | 0110110000000000
+ 0000000000110110 | 0000000000000000 | 0011011000000000
+ 0000000000011011 | 0000000000000000 | 0001101100000000
+ 0000000000001101 | 0000000000000000 | 0000110100000000
+ 0000000000000110 | 0000000000000000 | 0000011000000000
+ 0000000000000011 | 0000000000000000 | 0000001100000000
+ 0000000000000001 | 0000000000000000 | 0000000100000000
+(16 rows)
+
SELECT b::bit(15), b::bit(15) >> 1 AS bsr, b::bit(15) << 1 AS bsl
FROM BIT_SHIFT_TABLE ;
b | bsr | bsl
000000000000000 | 000000000000000 | 000000000000000
(16 rows)
+SELECT b::bit(15), b::bit(15) >> 8 AS bsr8, b::bit(15) << 8 AS bsl8
+ FROM BIT_SHIFT_TABLE ;
+ b | bsr8 | bsl8
+-----------------+-----------------+-----------------
+ 110110000000000 | 000000001101100 | 000000000000000
+ 011011000000000 | 000000000110110 | 000000000000000
+ 001101100000000 | 000000000011011 | 000000000000000
+ 000110110000000 | 000000000001101 | 000000000000000
+ 000011011000000 | 000000000000110 | 100000000000000
+ 000001101100000 | 000000000000011 | 110000000000000
+ 000000110110000 | 000000000000001 | 011000000000000
+ 000000011011000 | 000000000000000 | 101100000000000
+ 000000001101100 | 000000000000000 | 110110000000000
+ 000000000110110 | 000000000000000 | 011011000000000
+ 000000000011011 | 000000000000000 | 001101100000000
+ 000000000001101 | 000000000000000 | 000110100000000
+ 000000000000110 | 000000000000000 | 000011000000000
+ 000000000000011 | 000000000000000 | 000001100000000
+ 000000000000001 | 000000000000000 | 000000100000000
+ 000000000000000 | 000000000000000 | 000000000000000
+(16 rows)
+
CREATE TABLE VARBIT_SHIFT_TABLE(v BIT VARYING(20));
INSERT INTO VARBIT_SHIFT_TABLE VALUES (B'11011');
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v || B'0' AS BIT VARYING(6)) >>1 FROM VARBIT_SHIFT_TABLE;
00000000000000011011 | 00000000000000001101 | 00000000000000110110
(16 rows)
+SELECT v, v >> 8 AS vsr8, v << 8 AS vsl8
+ FROM VARBIT_SHIFT_TABLE ;
+ v | vsr8 | vsl8
+----------------------+----------------------+----------------------
+ 11011 | 00000 | 00000
+ 011011 | 000000 | 000000
+ 0011011 | 0000000 | 0000000
+ 00011011 | 00000000 | 00000000
+ 000011011 | 000000000 | 100000000
+ 0000011011 | 0000000000 | 1100000000
+ 00000011011 | 00000000000 | 01100000000
+ 000000011011 | 000000000000 | 101100000000
+ 0000000011011 | 0000000000000 | 1101100000000
+ 00000000011011 | 00000000000000 | 01101100000000
+ 000000000011011 | 000000000000000 | 001101100000000
+ 0000000000011011 | 0000000000000000 | 0001101100000000
+ 00000000000011011 | 00000000000000000 | 00001101100000000
+ 000000000000011011 | 000000000000000000 | 000001101100000000
+ 0000000000000011011 | 0000000000000000000 | 0000001101100000000
+ 00000000000000011011 | 00000000000000000000 | 00000001101100000000
+(16 rows)
+
DROP TABLE BIT_SHIFT_TABLE;
DROP TABLE VARBIT_SHIFT_TABLE;
-- Get/Set bit
FROM BIT_SHIFT_TABLE ;
SELECT b, b >> 1 AS bsr, b << 1 AS bsl
FROM BIT_SHIFT_TABLE ;
+SELECT b, b >> 8 AS bsr8, b << 8 AS bsl8
+ FROM BIT_SHIFT_TABLE ;
SELECT b::bit(15), b::bit(15) >> 1 AS bsr, b::bit(15) << 1 AS bsl
FROM BIT_SHIFT_TABLE ;
+SELECT b::bit(15), b::bit(15) >> 8 AS bsr8, b::bit(15) << 8 AS bsl8
+ FROM BIT_SHIFT_TABLE ;
CREATE TABLE VARBIT_SHIFT_TABLE(v BIT VARYING(20));
FROM VARBIT_SHIFT_TABLE ;
SELECT v, v >> 1 AS vsr, v << 1 AS vsl
FROM VARBIT_SHIFT_TABLE ;
+SELECT v, v >> 8 AS vsr8, v << 8 AS vsl8
+ FROM VARBIT_SHIFT_TABLE ;
DROP TABLE BIT_SHIFT_TABLE;
DROP TABLE VARBIT_SHIFT_TABLE;