gpt4 book ai didi

int - 相当于 Julia 中的 `int.bit_length()`

转载 作者:行者123 更新时间:2023-12-04 17:14:29 24 4
gpt4 key购买 nike

Python的 int.bit_length() 相当于什么?在 Julia ?

int.bit_length(): Return the number of bits necessary to represent an integer in binary, excluding the sign and leading zeros

最佳答案

在 Julia 中有 ndigits 功能。

ndigits(n::Integer; base::Integer=10, pad::Integer=1)

Compute the number of digits in integer n written in base base (base must not be in [-1, 0, 1]), optionally padded with zeros to a specified size (the result will never be less than pad).

Examples

julia> ndigits(12345)
5

julia> ndigits(1022, base=16)
3

julia> string(1022, base=16)
"3fe"

julia> ndigits(123, pad=5)
5


您想将它与 base = 2 一起使用关键字参数:
julia> ndigits(32, base = 2)
6

关于int - 相当于 Julia 中的 `int.bit_length()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58275985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com