Documentation/Calc Functions/BITLSHIFT

From The Document Foundation Wiki
Jump to: navigation, search

Function name:

BITLSHIFT

Category:

Mathematical

Summary:

Shifts a number left by the specified number of bits.

Syntax:

BITLSHIFT(Number; Shift)

Returns:

Returns a number shifted left by the specified number of bits.

Arguments:

Number is a positive integer less than 2 ^ 48 (281,474,976,710,656).

Shift is the number of positions the bits will be moved to the left. If shift is negative, it is synonymous with BITRSHIFT (Number; -Shift).

  • If either argument is a decimal number then its floor value is considered.
  • If Number is negative, the function returns an error value.

Additional details:

  • Shifting a number left is equivalent to adding zeros (0) to the right of the binary representation of the number. For example, a 3-bit shift to the left on the decimal value 6 converts its binary value (0110) to 0110000, or 48 in decimal.
  • Using a negative number as the Shift argument shifts the number of bits to the right. Hence it will return the same result as a positive Shift argument for the BITRSHIFT function.

Examples:

Formula Description Returns
=BITLSHIFT(6;3) 6 in binary is 0110 which when applied with left shift by 3-bit gives 0110000 or (0110 << 3 = 0110000) 48 (0110000)
=BITLSHIFT(6;-1) 6 in binary is 0110 which when applied with left shift by -1-bit gives 0011 which is equivalent to right shift by 1-bit or (0110 << -1 = 0011) 3 (0011)
=BITLSHIFT(6.123;3) floor of 6.123 is taken so 6 in binary is 0110 which when applied with left shift by 3-bit gives 0110000 or (0110 << 3 = 0110000) 48 (0110000)
=BITLSHIFT(6;3.6) 6 in binary is 0110 which when applied with left shift by 3-bit(floor of 3.6 is considered) gives 0110000 or (0110 << 3 = 0110000) 48 (0110000)
=BITLSHIFT(-6;3) Number is negative so function returns error value Err:502

Related LibreOffice functions:

BITRSHIFT

BITAND

BITXOR

ODF standard:

Section 6.6.3, Part 2

Equivalent Excel functions:

BITLSHIFT