将三个值包装成长的值

发布于 2025-01-24 15:47:22 字数 436 浏览 2 评论 0原文

我有以下生成哈希的位操作:

(z shl 28) or (y shl 14) or x // (z << 28 | y << 14 | x) in java

我希望能够从上面计算的哈希中推导x,y和z。我每次都可以得到Z和X,但是我很难获得y-它只能偶尔起作用。

z始终小于4。,x和y将不超过最大短值。

这就是我在做的事情:

    val hash = 684297131L // sample hash
    val z = hash shr 28
    val y = hash shr 14 // this works only sometimes
    val x = hash and 0xfff

我认为我在这里缺少一些简单的东西,任何帮助都对此表示赞赏。

I have the following bitwise operation that generates a hash:

(z shl 28) or (y shl 14) or x // (z << 28 | y << 14 | x) in java

I want to be able to deduce x, y and z from the hash calculated above. I can get Z and X every time, but I'm having trouble getting Y - it only works occasionally.

Z will always be less than 4. And x and y will be no bigger than the max short value.

This is what I'm doing:

    val hash = 684297131L // sample hash
    val z = hash shr 28
    val y = hash shr 14 // this works only sometimes
    val x = hash and 0xfff

I think I'm missing something simple here, any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-01-31 15:47:22

您的“哈希”看起来不太像哈希。它看起来更像是将3个字段打包成长时间。

您可以获取Xyz,产生相同的“哈希”:

val z = hash shr 28
val y = (hash shr 14) and 0x3fff
val x = hash and 0x3fff

这可能正是您想要的。有不同的数字可以产生相同的哈希,但最简单。

Your "hash" doesn't look too much like a hash. It looks more like packing 3 fields into a long.

You can get x, y, and z that produce the same "hash" like this:

val z = hash shr 28
val y = (hash shr 14) and 0x3fff
val x = hash and 0x3fff

This may be exactly what you want. There are different numbers that could produce the same hash, but these are the simplest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文