📜  Golang 中的 bits.Mul64()函数示例

📅  最后修改于: 2021-10-24 13:17:59             🧑  作者: Mango

bit.Mul64() Golang 中的函数用于查找 x 和 y 的 128 位乘积。此函数的执行时间不取决于输入。要访问此函数,需要在程序中导入 math/bits 包。

句法:

func Mul64(x, y uint64) (hi, lo uint64)

参数:该函数有两个uint64类型的参数,即x,y。

注: (hi, lo) = x * y
这里,hi 是乘积位的上半部分,lo 是返回的下半部分。

返回值:此函数返回 x 和 y 的128 位乘积

示例 1:

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

输出:

128-bit product of x and y :  0 375

示例 2:

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

输出:

Number 1: 10
Number 2: 30
Upper half: 0
Lower half: 300