Home/Instructions/Bit Extract
BEXT

RISC-V BEXT Instruction Details

Instruction ManualR-type

Extract single bit by register index

Instruction Syntax

bext rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
BZbsBit ManipulationSingle-Bit Operation

Instruction Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

BEXT uses opcode 0110011 (0x33), funct3 101, funct7 0100100. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 101 (0x5)
funct7: 0100100 (0x24)

Instruction Behavior

bext is a Zbs single-bit extract instruction. The bit index comes from the low log2(XLEN) bits of rs2.

Quick Understanding & Search Notes

bext is a Zbs single-bit extract instruction. The bit index comes from the low log2(XLEN) bits of rs2.

These instructions are part of a B-extension subset and operate on XLEN-wide integer register values.
The register-index form uses only the low log2(XLEN) bits of rs2 to select the bit.
bext/bexti returns 0 or 1; it does not preserve the original bit position.

Common Usage Scenarios

Address & Pointer

Understand this scenario with real code like «bext x10, x11, x12 ; x10 = (x11 >> (x12 & (XLEN-1))) & 1».

Bit Operations & Masks

Understand this scenario with real code like «bext x10, x11, x12 ; x10 = (x11 >> (x12 & (XLEN-1))) & 1».

Comparison & Detection

Understand this scenario with real code like «bext x10, x11, x12 ; x10 = (x11 >> (x12 & (XLEN-1))) & 1».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

The register-index form uses only the low log2(XLEN) bits of rs2 to select the bit.
bext/bexti returns 0 or 1; it does not preserve the original bit position.

FAQ

Does bext access memory?

No. It reads integer register operands and writes rd only.

How is the bit index selected for bext?

The low log2(XLEN) bits of rs2 select the bit, so higher bits do not extend the index range.