pyspark.sql.functions.bit_get#
- pyspark.sql.functions.bit_get(col, pos)[source]#
- Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative. - New in version 3.5.0. - Parameters
- Returns
- Column
- the value of the bit (0 or 1) at the specified position. 
 
 - Examples - Example 1: Get the bit with a literal position - >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([[1],[2],[3],[None]], ["value"]) >>> df.select("*", sf.bit_get("value", sf.lit(1))).show() +-----+-----------------+ |value|bit_get(value, 1)| +-----+-----------------+ | 1| 0| | 2| 1| | 3| 1| | NULL| NULL| +-----+-----------------+ - Example 2: Get the bit with a column position - >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([[1,2],[2,1],[3,None],[None,1]], ["value", "pos"]) >>> df.select("*", sf.bit_get(df.value, "pos")).show() +-----+----+-------------------+ |value| pos|bit_get(value, pos)| +-----+----+-------------------+ | 1| 2| 0| | 2| 1| 1| | 3|NULL| NULL| | NULL| 1| NULL| +-----+----+-------------------+