BITRSHIFT


Shifts a number to the right by a specified amount of bits and returns the result found after the shift.

Syntax:

BITRSHIFT(number, shift_amount)


number should be 0 or higher.


shift_amount is an integer.


Example:

If number contains 1 and shift_amount contains 2:

BITRSHIFT(1, 2)

returns 0


numberOne:


numberTwo:


Result:

0

Application:

Sensor Data Processing


Imagine you have a sensor that measures light intensity. The sensor outputs a digital value, which is then processed by a microcontroller. The raw sensor data is a decimal number, but for certain calculations, you need to quickly divide this value by powers of two (e.g., to scale the data or perform a simple average).


Let's say the sensor returns a value that needs to be divided by 4 for a specific part of the data analysis. Instead of using a standard division operation, which can be computationally more expensive, you can use the BITRSHIFT function, which performs a bitwise right shift. A right shift of 2 bits is equivalent to dividing the number by 22=4.


Here is how you can represent this in a spreadsheet program using the BITRSHIFT function:

Raw Sensor Value (Decimal)

Raw Sensor Value (Binary)

Shift Amount

Formula

Processed Value (Decimal)

Processed Value (Binary)

A
B
C
D
E
F
1
45
101101
2
BITRSHIFT(45, 2)
11
1011
2
62
111110
2
BITRSHIFT(62, 2)
15
1111
3
100
1100100
2
BITRSHIFT(100, 2)
25
11001

Explanation of the table:


  • Raw Sensor Value (Decimal): This is the value a sensor might output in its raw, unscaled form.
  • Raw Sensor Value (Binary): This is the binary representation of the decimal number.
  • Shift Amount: The number of bits we want to shift to the right. In this case, a shift of 2 bits divides the number by 4.
  • Formula: This is the BITRSHIFT function.
  • Processed Value (Decimal): The result of the bitwise right shift, which gives you the scaled value.
  • Processed Value (Binary): The binary representation of the result. As you can see, the bits have been shifted to the right, and the rightmost bits have been "dropped off."


In this example, the BITRSHIFT function provides a highly efficient way to perform a division by a power of two, which is a common task in fields like signal processing, computer graphics, and embedded systems.





This page is protected by Google reCAPTCHA. Privacy - Terms.
 
Built using Zapof