当前位置:网站首页>Chapter 8 operation bit and bit string (4)
Chapter 8 operation bit and bit string (4)
2022-06-24 14:22:00 【yaoxin521123】
List of articles
Chapter viii. Operation bits and bit strings ( Four )
Operate on a bit string implemented as an integer
Set bit
To create a new bit string stored as an integer , Please sum each bit 2 The power of :
set bitint = (2**2) + (2**5) + (2**10)
write bitint
1060
To set the bits in an existing bit string to 1, Please use $zboolean function ( Logic OR) The option to 7(arg1 ! arg2):
set bitint = $zboolean(bitint, 2**4, 7)
write bitint
1076
To set the bits in an existing bit string to 0, Please use $zboolean Options for functions 2(arg1 & ~arg2):
set bitint = $zboolean(bitint, 2**4, 2)
write bitint
1060
To switch bits in an existing bit string , Please use $zboolean function ( Logic XOR) The option to 6(arg1 ^ arg2):
set bitint = $zboolean(bitint, 2**4, 6)
write bitint
1076
set bitint = $zboolean(bitint, 2**4, 6)
write bitint
1060
Test whether the bit is set
To display a bit string as an integer , You can use the following methods , This method loops the bits and uses $zboolean function :
Class Util.BitUtil Extends %RegisteredObject
{
/// w ##class(Util.BitUtil).LogicalToDisplay(1)
ClassMethod LogicalToDisplay(bitint As %Integer)
{
s str = ""
for i = 0 : 1 {
q:((2 ** i) > bitint)
if $zboolean(bitint, 2 ** i, 1) {
s str = str _ 1
} else {
s str = str _ 0
}
}
q str
}
}
DHC-APP>w ##class(Util.BitUtil).LogicalToDisplay(101000)
00010001010100011
Find the setting bit
This method uses $Zlog The bit string() function sets which bits in a bit string are integers , This function returns with 10 The value of the base . This method deletes smaller and smaller bit string blocks , Until there is nothing left :
/// w ##class(Util.BitUtil).FindSetBits(2)
ClassMethod FindSetBits(bitint As %Integer)
{
s bits = ""
while (bitint '= 0) {
s bit = $zlog(bitint) \ $zlog(2)
s bits = bit _ " " _ bits
s bitint = bitint - (2 ** bit)
}
q bits
}
DHC-APP>w ##class(Util.BitUtil).FindSetBits(3)
0 1
Perform bitwise arithmetic
Use $zboolean Function performs bitwise logical operations on a bit string stored as an integer .
For this example , Suppose there are two bit strings a and b, Store as an integer , And one. LogicalToDisplay() Method , Such as Display Bits As defined in , Used to display these bits .
do ##class(User.BitInt).LogicalToDisplay(a)
100110111
do ##class(User.BitInt).LogicalToDisplay(b)
001000101
Use $zboolean Options for functions 7 Bitwise execution logic OR:
set c = $zboolean(a, b, 7)
do ##class(User.BitInt).LogicalToDisplay(c)
101110111
Use $zboolean Options for functions 1 Execute logic and... In place :
set d = $zboolean(a, b, 1)
do ##class(User.BitInt).LogicalToDisplay(d)
000000101
Convert to regular bit string
To convert a bit string stored as an integer to a regular bit string , Please use $factor function . For this example , Suppose there is a string of bits that is an integer bitint And a FindSetBits() Method , Such as Find Set Bits As defined in , To show which bits are set .
do ##class(User.BitInt).FindSetBits(bitint)
2 5 10
set bitstring = $factor(bitint)
zwrite bitstring
bitstring=$zwc(128,4)_$c(36,4,0,0)/*$bit(3,6,11)*/
Please note that , The bits in the regular bit string seem to have shifted one bit to the right , Because the bit string has no bits 0. The first bit in the bit string is bit 1.
边栏推荐
- Unit contour creation method
- Online text entity extraction capability helps applications analyze massive text data
- R语言plotly可视化:可视化模型在整个数据空间的分类轮廓线(等高线)、meshgrid创建一个网格,其中每个点之间的距离由mesh_size变量表示、使用不同的形状标签表征、训练、测试及分类标签
- Keras深度学习实战(11)——可视化神经网络中间层输出
- How to avoid placing duplicate orders
- A review of text contrastive learning
- Halcon 绘制区域 到图片中
- Kotlin shared mutable state and concurrency
- Return to new list
- Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
猜你喜欢

laravel8使用faker调用工厂填充数据

IDEA连接mysql自定义生成实体类代码

pgsql查询分组中某个字段最大或者最小的一条数据

MySQL log management, backup and recovery

box-sizing
![二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]](/img/d0/91ab1cc1851d7137a1cab3cf458302.png)
二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]

Go语言三个高效编程的技巧

Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!

Virtual machines on the same distributed port group but different hosts cannot communicate with each other
![Maximum path sum in binary tree [handle any subtree, then handle the whole tree]](/img/d0/91ab1cc1851d7137a1cab3cf458302.png)
Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
随机推荐
Redis interview questions
在CVS中恢复到早期版本
六月集训(第24天) —— 线段树
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
Zhiyuan community weekly 86: Gary Marcus talks about three linguistic factors that can be used for reference in large model research; Google puts forward the Wensheng graph model parti which is compar
GO语言-init()函数-包初始化
探索云原生数据库,纵观未来科技发展
`Thymeleaf`模板引擎全面解析
Keras深度学习实战(11)——可视化神经网络中间层输出
Common singleton mode & simple factory
如何避免下重复订单
[deep learning] storage form of nchw, nhwc and chwn format data
Explore cloud native databases and take a broad view of future technological development
鲲鹏arm服务器编译安装PaddlePaddle
IDEA连接mysql自定义生成实体类代码
数字臧品系统开发 NFT数字臧品系统异常处理源码分享
【深度学习】NCHW、NHWC和CHWN格式数据的存储形式
A review of text contrastive learning
Return to new list
10_那些格调很高的个性签名