我有以下问题:我有一个 C++ 中的十六进制数(数据类型:std::uint64_t),该十六进制数包含从 1 到给定 n 的所有数字。我们还给出了另一个数字 d <= n。是否可以将十六进制数中大于或等于n的所有数字减1?这是我所期待的一个例子:
hex = 0x42513, d = 3 -> Result : 0x42513
- 0x10101 <- the zero's are there because the digits
---------- over them are smaller than 3
0x32412
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用带有左移和右移的 for 循环来实现结果,但现在我感兴趣是否存在不使用循环而是仅使用位操作的解决方案?