gpt4 book ai didi

neo4j - Neo4j 密码查询中的按位运算替代方案

转载 作者:行者123 更新时间:2023-12-02 19:19:32 25 4
gpt4 key购买 nike

我需要在密码查询中执行按位“与”操作。 cypher 似乎不支持按位运算。有什么替代方案的建议吗?这就是我想要检测的...例如,268 是 (2^8 + 2^3 + 2^2),正如您所看到的,2^3 = 8 是我原始数字的一部分。所以如果我使用按位 AND 它将是 (100001100) & (1000) = 1000 这样我就可以检测 8 是否是 268 的一部分。如果没有按位支持,我该如何做到这一点?有什么建议么?我需要用密码来完成此操作。

最佳答案

使用 cypher 执行此类测试的另一种方法是将十进制值转换为表示所设置位的小数集合。

// convert the binary number to a collection of decimal parts
// create an index the size of the number to convert
// create a collection of decimals that correspond to the bit locations
with '100001100' as number
, [1,2,4,8,16,32,64,128,256,512,1024,2048,4096] as decimals
with number
, range(length(number)-1,0,-1) as index
, decimals[0..length(number)] as decimals

// map the bits to decimal equivalents
unwind index as i
with number, i, (split(number,''))[i] as binary_placeholder, decimals[-i-1] as decimal_placeholder

// multiply the decimal value by the bits that are set
with collect(decimal_placeholder * toInt(binary_placeholder)) as decimal_placeholders

// filter out the zero values from the collection
with filter(d in decimal_placeholders where d > 0) as decimal_placeholders
return decimal_placeholders

这是返回的示例。

enter image description here

然后,当您想测试该数字是否为小数时,只需测试集合中是否存在实际的小数即可。

with [4, 8, 256] as decimal_placeholders
, 8 as decimal_to_test
return
case
when decimal_to_test in decimal_placeholders then
toString(decimal_to_test) + ' value bit is set'
else
toString(decimal_to_test) + ' value bit is NOT set'
end as bit_set_test

关于neo4j - Neo4j 密码查询中的按位运算替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35226158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com