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 takes two parameter of uint type, i.e., x, y.

Note: (hi, lo) = x * y
Here, hi is the product bits’ upper half and, lo is the lower half returned.

Return Value: This function returns the full-width product of x and y.



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate
// bits.Mul() Function
package main
  
import (
    "fmt"
    "math/bits"
)
  
// Main function
func main() {
  
    // Using Mul() function
    hi, lo := bits.Mul(5, 10)
    fmt.Println("Full-width product of x and y : ", hi, lo)
  
}

chevron_right


Output:

Full-width product of x and y :  0 50

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Golang program to illustrate 
// bits.Mul() Function 
package main 
     
import ( 
    "fmt"
    "math/bits"
     
// Main function 
func main() { 
     
    // Using Mul() function 
    const a, b = 34, 56
    hi, lo  := bits.Mul(a, b) 
    fmt.Println("Number 1:", a) 
    fmt.Println("Number 2:", b) 
    fmt.Println("Upper half:", hi) 
    fmt.Println("Lower half:", lo)  
     
}

chevron_right


Output:

Number 1: 34
Number 2: 56
Upper half: 0
Lower half: 1904



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.