Standard library / math/bits

bits.Add()

Adds two unsigned words and a carry-in (0 or 1), returning low word and carry-out. Native uint width is architecture-dependent; local validation uses 64 bits. Expected stdout: '0 1\n'.

Formal Syntax & Structure

go syntaxgo
func Add(x, y, carry uint) (sum, carryOut uint)

Parameters & Attributes

NameTypeDescription
xuintFirst input operand (or sole input if unary).
yuintSecond input operand.
carryuintCarry-in bit; must be 0 or 1.

Return Value

(sum, carryOut uint)

Adds two unsigned words and a carry-in (0 or 1), returning low word and carry-out. Native uint width is architecture-dependent; local validation uses 64 bits.

Working Example

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