Open In App

bits.Mul32() Function in Golang with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

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 function takes two parameter of uint32 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 64-bit product of x and y.

Example 1:




// Golang program to illustrate 
// bits.Mul32() Function 
package main 
     
import ( 
    "fmt"
    "math/bits"
     
// Main function 
func main() { 
     
    // Using Mul32() function 
    hi, lo  := bits.Mul32(7, 2) 
    fmt.Println("64-bit product of x and y : ", hi, lo) 
     
}


Output:

64-bit product of x and y :  0 14

Example 2:




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


Output:

Number 1: 10
Number 2: 20
Upper half: 0
Lower half: 200


Last Updated : 28 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads