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) *IntParameters & Attributes
| Name | Type | Description |
|---|---|---|
| x | *Int | Numeric operand supplied to this method. |
| i | int | Zero-based bit index. |
| b | uint | Bit 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))}