当前位置:网站首页>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.
边栏推荐
- 高薪程序员&面试题精讲系列115之Redis缓存如何实现?怎么发现热key?缓存时可能存在哪些问题?
- PgSQL queries the largest or smallest data of a field in a group
- 10 Ces autographes très stylisés.
- The "little giant" specialized in special new products is restarted, and the "enterprise cloud" digital empowerment
- 15 differences between MES in process and discrete manufacturing enterprises (Part 2)
- How to evaluate domestic reporting tools and Bi software
- 4 reasons for "safe left shift"
- Explore cloud native databases and take a broad view of future technological development
- OpenHarmony 1
- 【环境搭建】zip 分卷压缩
猜你喜欢

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

厨卫电器行业B2B交易协同管理平台开发,优化企业库存结构

Common sense knowledge points

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!

Convolution kernel and characteristic graph visualization

Method of inputting dots under letters in markdown/latex

`Thymeleaf ` template engine comprehensive analysis

Win10 system problems

Go language concurrency model mpg model

postgresql之词法分析简介
随机推荐
Telecommuting: camping at home office gadgets | community essay solicitation
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
laravel8使用faker调用工厂填充数据
【环境搭建】zip 分卷压缩
[environment setup] zip volume compression
Go language - use of goroutine coroutine
[untitled]
How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup
遠程辦公之:在家露營辦公小工具| 社區征文
leetcode 139. Word Break 单词拆分(中等)
第八章 操作位和位串(四)
MySQL log management, backup and recovery
【LeetCode】10、正则表达式匹配
ESP32系列--ESP32各个系列对比
R语言plotly可视化:可视化模型在整个数据空间的分类轮廓线(等高线)、meshgrid创建一个网格,其中每个点之间的距离由mesh_size变量表示、使用不同的形状标签表征、训练、测试及分类标签
P2pdb white paper
box-sizing
二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]
The difference between V-IF and v-show
Kotlin shared mutable state and concurrency