Standard library / math/bits

bits.Sub32()

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out. Expected stdout: 'true 1\n'.

Formal Syntax & Structure

go syntaxgo
func Sub32(x, y, borrow uint32) (diff, borrowOut uint32)

Parameters & Attributes

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

Return Value

(diff, borrowOut uint32)

Subtracts y and borrow-in (0 or 1) from x; returns low word and borrow-out.

Working Example

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