bits.Sub32() Function in Golang with Examples Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The bits.Sub32() Function in Golang is used to find the difference of a, b and borrow, i.e. diff = a - b - borrow. Here the borrow must be 0 or 1; otherwise, the behavior is undefined. To access this function, one needs to imports the math/bits package in the program. The return value of the borrowOutput will be always 0 or 1 in any case.Syntax: func Sub32(a, b, borrow uint32) (diff, borrowOut uint32) Parameters: This function takes three parameters of uint32 type, i.e., a, b, and borrow. The value of borrow parameter is either 1 or 0.Return Value: This function return two values of uint32 type, i.e., diff and borrowOut. Here diff contains the result of a - b - borrow and borrowOut is either 1 or 0.Example 1: C // Golang program to illustrate bits.Sub32() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Finding diff and borrowOut // of the specified numbers // Using Sub32() function nvalue_1, borrowOut := bits.Sub32(13, 8, 1) fmt.Println("Diff:", nvalue_1) fmt.Println("BorrowOut :", borrowOut) } Output: Diff: 4 BorrowOut : 0 Example 2: Here, you can see that the result is not as expected as we have taken the value of borrow as 3. So if we are taking borrow input other than 1 and 0 then the behavior will be undefined. C // Golang program to illustrate bits.Sub32() Function package main import ( "fmt" "math/bits" ) // Main function func main() { // Finding diff and borrowOut // of the specified numbers // Using Sub32() function var a, b, borrow uint32 = 4, 15, 3 Diff, borrowOut := bits.Sub32(a, b, borrow) fmt.Println("Number 1:", a) fmt.Println("Number 2:", b) fmt.Println("Borrow :", borrow) fmt.Println("Diff:", Diff) fmt.Println("BorrowOut :", borrowOut) } Output: Number 1: 4 Number 2: 15 Borrow : 3 Diff: 4294967282 BorrowOut : 1 Comment More infoAdvertise with us Next Article bits.Sub32() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-bits Similar Reads bits.Sub() Function in Golang with Examples The bits.Sub() Function in Golang is used to find the difference of a, b and borrow, i.e. diff = a - b - borrow. Here the borrow must be 0 or 1; otherwise, the behavior is undefined. To access this function, one needs to imports the math/bits package in the program. The return value of the borrowOut 2 min read bits.Sub64() Function in Golang with Examples The bits.Sub64() Function in Golang is used to find the difference of a, b and borrow, i.e. diff = a - b - borrow.Here the borrow must be 0 or 1; otherwise, the behavior is undefined. To access this function, one needs to imports the math/bits package in the program. The return value of the borrowOu 2 min read bits.Mul32() Function in Golang with Examples bits.Mul32() Function in Golang is used to find the 64-bit product of x and y. The execution time of this function does not depend on the inputs. To access this function, one needs to imports the math/bits package in the program. Syntax: func Mul32(x, y uint32) (hi, lo uint32) Parameters: This funct 2 min read bits.Len32() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Len32() function which is used to find the minimum number of bits required to represent a and the result 2 min read bits.Rem32() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Rem32() function which is used to find the remainder of (h, l) divided by a. This function will panics if 2 min read bits.Mul() Function in Golang with Examples bits.Mul() Function in Golang is used to find the full-width product of x and y. The execution time of this function does not depend on the inputs. To access this function, one needs to imports the math/bits package in the program. Syntax: func Mul(x, y uint) (hi, lo uint) Parameters: This function 2 min read bits.OnesCount32() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides the OnesCount32() function which is used to find the number of one bits in a. To access the OnesCount32() 2 min read bits.Mul64() Function in Golang with Examples bits.Mul64() Function in Golang is used to find the 128-bit product of x and y. The execution time of this function does not depend on the inputs. To access this function, one needs to imports the math/bits package in the program. Syntax: func Mul64(x, y uint64) (hi, lo uint64) Parameters: This func 2 min read bits.Reverse32() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Reverse32() function which is used to find the reversed order of the value of a. To access the Reverse32( 1 min read bits.Len() Function in Golang with Examples Go language provides inbuilt support for bits to implement bit counting and manipulation functions for the predeclared unsigned integer types with the help of bits package. This package provides Len() function which is used to find the minimum number of bits required to represent a and the result is 2 min read Like