bits.Rem() 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 Rem() function which is used to find the remainder of (h, l) divided by a. This function will panics if a == 0 (division by zero) and it doesn’t panic if quotient overflow. To access Rem() function you need to add a math/bits package in your program with the help of the import keyword.

Syntax:

func Rem(h, l, a uint) uint

Parameters: This function takes three parameters of uint type, i.e., h, l, and a.

Return Value: This function returns the remainder of (h, l) divided by a.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate bits.Rem() Function
package main
  
import (
    "fmt"
    "math/bits"
)
  
// Main function
func main() {
  
    // Finding remainder
    // Using Rem() function
    r := bits.Rem(8, 9, 3)
    fmt.Println("Remainder:", r)
  
}

chevron_right


Output:

Remainder: 2

Example 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate bits.Rem() Function
package main
  
import (
    "fmt"
    "math/bits"
)
  
// Main function
func main() {
  
    // Finding remainder
    // Using Rem() function
    var h, l, a uint = 3, 5, 2
    r := bits.Rem(h, l, a)
    fmt.Println("Number 1:", h)
    fmt.Println("Number 2:", l)
    fmt.Println("Number 3:", a)
    fmt.Println("Remainder:", r)
  
}

chevron_right


Output:

Number 1: 3
Number 2: 5
Number 3: 2
Remainder: 1



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.