vbnet 位数组bitarray vb中数组排序的方法
yuyutoo 2024-10-12 01:35 13 浏览 0 评论
BitArray类管理位值的压缩数组,它表示为布尔值,其中true表示该位为(1),false表示位为off(0)。
它用于需要存储位但不提前知道位数。 您可以通过使用从零开始的整数索引来访问BitArray集合中的项目。
BitArray类的属性和方法
下表列出了BitArray类的一些常用属性:
属性 描述
Count Gets the number of elements contained in the BitArray.
获取BitArray中包含的元素数。
IsReadOnly Gets a value indicating whether the BitArray is read-only.
获取一个指示BitArray是否为只读的值。
Item Gets or sets the value of the bit at a specific position in the BitArray.
获取或设置位在BitArray中特定位置的值。
Length Gets or sets the number of elements in the BitArray.
获取或设置BitArray中的元素数。
下表列出了BitArray类的一些常用方法:
S.N 方法名称和用途
1
Public Function And (value As BitArray) As BitArray
Performs the bitwise AND operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.
对当前BitArray中的元素与指定的BitArray中的相应元素执行按位AND运算。
2
Public Function Get (index As Integer) As Boolean
Gets the value of the bit at a specific position in the BitArray.
获取位在BitArray中特定位置的值。
3
Public Function Not As BitArray
Inverts all the bit values in the current BitArray, so that elements set to true are changed to false, and elements set to false are changed to true.
反转当前BitArray中的所有位值,以便将设置为true的元素更改为false,将设置为false的元素更改为true。
4
Public Function Or (value As BitArray) As BitArray
Performs the bitwise OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.
对当前BitArray中的元素与指定的BitArray中的相应元素执行按位或运算。
5
Public Sub Set (index As Integer, value As Boolean )
Sets the bit at a specific position in the BitArray to the specified value.
将BitArray中特定位置的位设置为指定值。
6
Public Sub SetAll (value As Boolean)
Sets all bits in the BitArray to the specified value.
将BitArray中的所有位设置为指定的值。
7
Public Function Xor (value As BitArray) As BitArray
Performs the bitwise eXclusive OR operation on the elements in the current BitArray against the corresponding elements in the specified BitArray.
对当前BitArray中的元素与指定的BitArray中的相应元素执行逐位异或操作。
示例:
下面的例子演示了使用BitArray类:
Module collections
Sub Main()
'creating two bit arrays of size 8
Dim ba1 As BitArray = New BitArray(8)
Dim ba2 As BitArray = New BitArray(8)
Dim a() As Byte = {60}
Dim b() As Byte = {13}
'storing the values 60, and 13 into the bit arrays
ba1 = New BitArray(a)
ba2 = New BitArray(b)
'content of ba1
Console.WriteLine("Bit array ba1: 60")
Dim i As Integer
For i = 0 To ba1.Count
Console.Write("{0 } ", ba1(i))
Next i
Console.WriteLine()
'content of ba2
Console.WriteLine("Bit array ba2: 13")
For i = 0 To ba2.Count
Console.Write("{0 } ", ba2(i))
Next i
Console.WriteLine()
Dim ba3 As BitArray = New BitArray(8)
ba3 = ba1.And(ba2)
'content of ba3
Console.WriteLine("Bit array ba3 after AND operation: 12")
For i = 0 To ba3.Count
Console.Write("{0 } ", ba3(i))
Next i
Console.WriteLine()
ba3 = ba1.Or(ba2)
'content of ba3
Console.WriteLine("Bit array ba3 after OR operation: 61")
For i = 0 To ba3.Count
Console.Write("{0 } ", ba3(i))
Next i
Console.WriteLine()
Console.ReadKey()
End Sub
End Module
当上述代码被编译和执行时,它产生以下结果:
Bit array ba1: 60
False False True True True True False False
Bit array ba2: 13
True False True True False False False False
Bit array ba3 after AND operation: 12
False False True True False False False False
Bit array ba3 after OR operation: 61
True False True True False False False False
相关推荐
- Python操作Word文档神器:python-docx库从入门到精通
-
Python操作Word文档神器:python-docx库从入门到精通动动小手,点击关注...
- Python 函数调用从入门到精通:超详细定义解析与实战指南 附案例
-
一、函数基础:定义与调用的核心逻辑定义:函数是将重复或相关的代码块封装成可复用的单元,通过函数名和参数实现特定功能。它是Python模块化编程的基础,能提高代码复用性和可读性。定义语法:...
- 等这么长时间Python背记手册终于来了,入门到精通(视频400集)
-
本文毫无套路!真诚分享!前言:无论是学习任何一门语言,基础知识一定要扎实,基础功非常的重要,找一个有丰富编程经验的老师或者师兄带着你会少走很多弯路,你的进步速度也会快很多,无论我们学习的目的是什么,...
- 图解Python编程:从入门到精通系列教程(附全套速查表)
-
引言本系列教程展开讲解Python编程语言,Python是一门开源免费、通用型的脚本编程语言,它上手简单,功能强大,它也是互联网最热门的编程语言之一。Python生态丰富,库(模块)极其丰富,这使...
- Python入门教程(非常详细)从零基础入门到精通,看完这一篇就够
-
本书是Python经典实例解析,采用基于实例的方法编写,每个实例都会解决具体的问题和难题。主要内容有:数字、字符串和元组,语句与语法,函数定义,列表、集、字典,用户输入和输出等内置数据结构,类和对象,...
- Python函数全解析:从入门到精通,一文搞定!
-
1.为什么要用函数?函数的作用:封装代码,提高复用性,减少重复,提高可读性。...
- Python中的单例模式:从入门到精通
-
Python中的单例模式:从入门到精通引言单例模式是一种常用的软件设计模式,它保证了一个类只有一个实例,并提供一个全局访问点。这种模式通常用于那些需要频繁创建和销毁的对象,比如日志对象、线程池、缓存等...
- 【Python王者归来】手把手教你,Python从入门到精通!
-
用800个程序实例、5万行代码手把手教你,Python从入门到精通!...
- Python从零基础入门到精通:一个月就够了
-
如果想从零基础到入门,能够全职学习(自学),那么一个月足够了。...
- Python 从入门到精通:一个月就够了
-
要知道,一个月是一段很长的时间。如果每天坚持用6-7小时来做一件事,你会有意想不到的收获。作为初学者,第一个月的月目标应该是这样的:熟悉基本概念(变量,条件,列表,循环,函数)练习超过30个编...
- Python零基础到精通,这8个入门技巧让你少走弯路,7天速通编程!
-
Python学习就像玩积木,从最基础的块开始,一步步搭建出复杂的作品。我记得刚开始学Python时也是一头雾水,走了不少弯路。现在回头看,其实掌握几个核心概念,就能快速入门这门编程语言。来聊聊怎么用最...
- 神仙级python入门教程(非常详细),从0到精通,从看这篇开始!
-
python入门虽然简单,很多新手依然卡在基础安装阶段,大部分教程对一些基础内容都是一带而过,好多新手朋友,对一些基础知识常常一知半解,需要在网上查询很久。...
- Python类从入门到精通,一篇就够!
-
一、Python类是什么?大家在生活中应该都见过汽车吧,每一辆真实存在、能在路上跑的汽车,都可以看作是一个“对象”。那这些汽车是怎么生产出来的呢?其实,在生产之前,汽车公司都会先设计一个详细的蓝图...
- 学习Python从入门到精通:30天足够了,这才是python基础的天花板
-
当年2w买的全套python教程用不着了,现在送给有缘人,不要钱,一个月教你从入门到精通1、本套视频共487集,本套视频共分4季...
- 30天Python 入门到精通(3天学会python)
-
以下是一个为期30天的Python入门到精通学习课程,专为零基础新手设计。课程从基础语法开始,逐步深入到面向对象编程、数据处理,最后实现运行简单的大语言模型(如基于HuggingFace...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- mybatis plus (70)
- scheduledtask (71)
- css滚动条 (60)
- java学生成绩管理系统 (59)
- 结构体数组 (69)
- databasemetadata (64)
- javastatic (68)
- jsp实用教程 (53)
- fontawesome (57)
- widget开发 (57)
- vb net教程 (62)
- hibernate 教程 (63)
- case语句 (57)
- svn连接 (74)
- directoryindex (69)
- session timeout (58)
- textbox换行 (67)
- extension_dir (64)
- linearlayout (58)
- vba高级教程 (75)
- iframe用法 (58)
- sqlparameter (59)
- trim函数 (59)
- flex布局 (63)
- contextloaderlistener (56)