将 UInt64 数组转换为 BitVector

问题描述 投票:0回答:1

我最近发现我可以使用

UInt64
获取
BitVector
chunks
的“支持数组”。但是,我想采取相反的方式 - 给定一个一维数组
UInt64
,使用某些函数
BitVector
构造一个
foo
,这样

foo(x.chunks) == x

有这样的功能吗?

arrays julia bitset
1个回答
4
投票

this这样的东西有用吗?

function foo(v::Vector{UInt64})
    siz = sizeof(v)
    bv = falses(siz << 6)
    unsafe_copyto!(reinterpret(Ptr{UInt64}, pointer(bv.chunks)), pointer(v), siz)
    bv
end

如果需要,它们还提供重载来设置结果中的位数。

    

© www.soinside.com 2019 - 2024. All rights reserved.