简体   繁体   English

VB.NET - 将 UShort 转换为布尔数组

[英]VB.NET - Convert UShort into boolean array

I'm updating some old code written by another programmer, and i need to do some changes.我正在更新另一个程序员编写的一些旧代码,我需要做一些更改。 I have an unsigned integer stored into Short var and need to get its binary code in an array of bool.我有一个无符号整数存储在 Short var 中,需要在 bool 数组中获取其二进制代码。

How can i do this?我怎样才能做到这一点?

In addition to Trevor's answer, you can use a BitVector32 as well:除了 Trevor 的回答之外,您还可以使用BitVector32

Dim myValue As UShort = 32
Dim bVector As New BitVector32(CInt(myValue))

BitVector32 is slightly more efficient than BitArray but is limited to 32 bits. BitVector32BitArray效率稍高,但仅限于 32 位。 BitVector32 allows you to create sections in the bits for different purposes and treat them as flags. BitVector32允许您为不同的目的在位中创建部分并将它们视为标志。

try this perhaps也许试试这个

    Dim MyShort As uShort = 32
    Dim oByteArray As New System.Collections.BitArray(System.BitConverter.GetBytes(MyShort))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM