Standard library / math/big

big.Int.SetBit()

Copy x while setting bit i to zero or one. Negative index or other bit values panic. This method writes to the receiver (use a separate destination to preserve inputs when needed). Expected stdout: '10\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Int) SetBit(x *Int, i int, b uint) *Int

Parameters & Attributes

NameTypeDescription
x*IntNumeric operand supplied to this method.
iintZero-based bit index.
buintBit value, either zero or one.

Return Value

*Int

Returns the result described above; see the example for the observed behavior.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/big")
func main() {  fmt.Println(new(big.Int).SetBit(big.NewInt(8), 1, 1))}
Go Reference