Related Articles
bits.Div32() Function in Golang with Examples
• Last Updated : 19 Apr, 2020

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 Div32() function which is used to find the quotient and remainder of (a, b) divided by c, i.e., q = (a, b)/c, r = (a, b)%c with the dividend bits’ upper half in parameter a and the lower half in parameter b. This function panics if c == 0 (division by zero) or c <= a (quotient overflow). To access Div32() function you need to add a math/bits package in your program with the help of the import keyword.

Syntax:

`func Div32(a, b, c uint32) (q, r uint32)`

Parameters: This function takes three parameters of uint32 type, i.e., a, b, and c.

Return Value: This function return two values of uint32 type, i.e., q and r. Here q is known as quotient and r is known as the remainder.

Example 1:

 `// Golang program to illustrate bits.Div32() Function``package main`` ` `import (``    ``"fmt"``    ``"math/bits"``)`` ` `// Main function``func main() {`` ` `    ``// Finding quotient and remainder``    ``// Using Div32() function``    ``q, r := bits.Div32(10, 12, 11)``    ``fmt.Println(``"Quotient:"``, q)``    ``fmt.Println(``"Remainder:"``, r)`` ` `}`

Output:

```Quotient: 3904515724
Remainder: 8
```

Example 2:

 `// Golang program to illustrate bits.Div32() Function`` ` `package main`` ` `import (``    ``"fmt"``    ``"math/bits"``)`` ` `// Main function``func main() {`` ` `    ``// Finding quotient and remainder``    ``// Using Div32() function``    ``var a, b, c uint32 = 1, 13, 5``    ``q, r := bits.Div32(a, b, c)``    ``fmt.Println(``"Number 1:"``, a)``    ``fmt.Println(``"Number 2:"``, b)``    ``fmt.Println(``"Number 3:"``, c)``    ``fmt.Println(``"Quotient:"``, q)``    ``fmt.Println(``"Remainder:"``, r)`` ` `}`

Output:

```Number 1: 1
Number 2: 13
Number 3: 5
Quotient: 858993461
Remainder: 4
```

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.

My Personal Notes arrow_drop_up