当前位置:网站首页>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.
边栏推荐
- Development of B2B transaction collaborative management platform for kitchen and bathroom electrical appliance industry and optimization of enterprise inventory structure
- Go language concurrency model mpg model
- 根据前序&中序遍历生成二叉树[左子树|根|右子树的划分/生成/拼接问题]
- 六石管理学:垃圾场效应:工作不管理,就会变成垃圾场
- Online text entity extraction capability helps applications analyze massive text data
- MySQL log management, backup and recovery
- Puzzle (016.2) finger painting Galaxy
- Solution of channel management system for food and beverage industry: realize channel digital marketing layout
- SAP Marketing Cloud 功能概述(四)
- 文本对比学习综述
猜你喜欢

postgresql之List

Common singleton mode & simple factory

How to avoid placing duplicate orders

卷积核、特征图可视化

从谭浩强《C程序设计》上摘录的ASCII码表(常用字符与ASCII代码对照表)

How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup

Development of B2B transaction collaborative management platform for kitchen and bathroom electrical appliance industry and optimization of enterprise inventory structure

Three efficient programming skills of go language

tongweb使用之端口冲突处理办法

MySQL log management, backup and recovery
随机推荐
Detailed explanation of redis data types
10 Ces autographes très stylisés.
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?
Kunpeng arm server compilation and installation paddlepaddle
Common sense knowledge points
【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
第八章 操作位和位串(四)
conda和pip命令
CONDA and pip commands
[leetcode] 10. Regular expression matching
R语言构建回归模型诊断(正态性无效)、进行变量变换、使用car包中的powerTransform函数对目标变量进行Box-Cox变换(Box–Cox transform to normality)
文本对比学习综述
Getting to know cloud native security for the first time: the best guarantee in the cloud Era
Telecommuting: camping at home office gadgets | community essay solicitation
leetcode.12 --- 整数转罗马数字
在线文本实体抽取能力,助力应用解析海量文本数据
leetcode:1504. Count the number of all 1 sub rectangles
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
Linux 安装 CenOS7 MySQL - 8.0.26
SaaS management system solution of smart Park: enabling the park to realize information and digital management