Standard library / math/bits

bits.Add32()

Adds two unsigned words and a carry-in (0 or 1), returning low word and carry-out. Expected stdout: '0 1\n'.

Formal Syntax & Structure

go syntaxgo
func Add32(x, y, carry uint32) (sum, carryOut uint32)

Parameters & Attributes

NameTypeDescription
xuint32First input operand (or sole input if unary).
yuint32Second input operand.
carryuint32Carry-in bit; must be 0 or 1.

Return Value

(sum, carryOut uint32)

Adds two unsigned words and a carry-in (0 or 1), returning low word and carry-out.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/bits")
func main() {  s, c := bits.Add32(^uint32(0), 1, 0)  fmt.Println(s, c)}
Go Reference