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 Add64() function which is used to find the sum with the carry of a, b and carry, i.e, sum = a + b + carry. Here the value of carry must be 0 or 1, otherwise, the behavior is undefined. To access the Add64() function you need to add a math/bits package in your program with the help of the import keyword.
Syntax:func Add64(a, b, carry uint64) (sum, carryout uint64)
Parameters: This function takes three parameters of uint64 type, i.e., a, b, and carry. The value of carry parameter is either 1 or 0.
Return Value: This function return two values of uint64 type, i.e., sum and carryout. Here sum contains the result of a + b + carry and carryout is either 1 or 0.
Sum: 58 Carry: 0
Number 1: 34 Number 2: 56 Carry: 0 Sum: 90 Carry: 0
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.