当前位置:网站首页>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.
边栏推荐
- IDEA连接mysql自定义生成实体类代码
- 卷积核、特征图可视化
- The difference between V-IF and v-show
- GO语言-goroutine协程的使用
- How to implement redis cache of highly paid programmers & interview questions series 115? How do I find a hot key? What are the possible problems with caching?
- Development of B2B transaction collaborative management platform for kitchen and bathroom electrical appliance industry and optimization of enterprise inventory structure
- Keras深度学习实战(11)——可视化神经网络中间层输出
- Unit contour creation method
- 【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
- Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
猜你喜欢

Defeat the binary tree!

P2pdb white paper
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers

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

Second, the examinee must see | consolidate the preferred question bank to help the examinee make the final dash

postgresql之词法分析简介

The "little giant" specialized in special new products is restarted, and the "enterprise cloud" digital empowerment

unity 等高线创建方法
![[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX](/img/d1/4b21c8049f0377b54a18a9b267432e.png)
[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX
随机推荐
R language constructs regression model diagnosis (normality is invalid), performs variable transformation, and uses powertransform function in car package to perform box Cox transform to normality on
leetcode:1504. 统计全 1 子矩形的个数
MySQL log management, backup and recovery
Go language - use of goroutine coroutine
PgSQL queries the largest or smallest data of a field in a group
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
R语言plotly可视化:使用plotly可视化数据划分后的训练集和测试集、使用不同的形状标签表征、训练集、测试集、以及数据集的分类标签(Display training and test split
数字臧品系统开发 NFT数字臧品系统异常处理源码分享
在线文本实体抽取能力,助力应用解析海量文本数据
Telecommuting: camping at home office gadgets | community essay solicitation
Jupyter notebook操作
MySQL日志管理、备份与恢复
不要小看了积分商城,它的作用可以很大
Daily knowledge popularization
10_那些格调很高的个性签名
JS remove string spaces
C language ---18 function (user-defined function)
pip uninstall all packages except builtin package
根据前序&中序遍历生成二叉树[左子树|根|右子树的划分/生成/拼接问题]
R语言构建回归模型诊断(正态性无效)、进行变量变换、使用car包中的powerTransform函数对目标变量进行Box-Cox变换(Box–Cox transform to normality)