递增字符串中的单个字符
我不知道我的标题是否正确,所以如果我错了,请纠正我,我会更改我的标题。
我有一个字符串,在这个例子中我将使用:
"8ce4b16b"
我想将位(我认为)沿着 1 移动,所以字符串将是:
"9df5c27c"
有什么想法吗?
编辑:
正如您所知,这些字符串是十六进制的。所以它永远不会到达z。 我想做的就是在数字中添加一个数字,然后在字母表中前进一步,所以 a->b、f->g 等
如果数字是 9,则有一个条件将其保留为 9
。输出不需要是十六进制。
该字符串也只是一个示例。它是 MD5 加密的一部分。
I dont know if I have the correct tiltle for this, so please correct me if I am wrong and I will change my title.
I have a string, for this example I will use:
"8ce4b16b"
I would like to shift the bits (I think) along 1 so the string would be:
"9df5c27c"
Any Ideas?
EDIT:
Just so you know, these strings are hex. So it will never reach z.
All I want to do is add a number to the numbers and progress one step through the alphabet so a->b, f->g ect ect
If the number is 9 there will be a condition to keep it as 9.
The output DOES NOT need to be a hex.
Also the string is only an example. It is part of an MD5 encryption.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
转换
字符串
?这听起来像是std::transform()
:您希望对字符施加的任何限制都可以在
increment()
函数中实现,如所示。另一方面,如果您希望将字符串视为十六进制数字并向其中添加
0x11111111
:在此
字符串
的构造过程中不会移动任何位。Transform a
string
? This sounds like a job forstd::transform()
:Any limits you wish to impose on the characters can be implemented in the
increment()
function, as demonstrated.If, on the other hand, you wish to treat the string as a hexadecimal number and add
0x11111111
to it:No bits were shifted in the construction of this
string
.看起来您只是将 0x11111111 添加到整数中。但是你能准确指定你的输入有什么类型吗?当“f”或“9”加一时,结果应该是什么?
It looks like you simply added 0x11111111 to the integer. But can you specify precisely what tpye your input has? And what the result should be when you add one to "f" or "9"?
这不是移位...移位一位会将字值乘以 2。您只需将每个十六进制值增加 1,这可以通过将
0x11111111
添加到双字来完成。例如,如果您将值
0x8ce4b16b
(这会将上面打印的值视为十六进制的 4 字节双字),将其移动一位,您将最终为0x19C962D6
。但是,如果您只是想增加双字的每个半字节(十六进制数字中的每个单独值代表 4 位或一个半字节),则必须向每个半字节添加 0x1 的偏移量。此外,十六进制字中没有
G
值...您的值是0->9
,然后是A->F< /code>,其中
F
代表以 10 为基数的值 15。最后,当您将0x1
添加到0xF
时,您将换行大约0x0
。That's not shifting the bits ... shifting a bit multiplies a word value by 2. You're simply incrementing each hex value by 1, and that can be done by adding
0x11111111
to your dword.For instance, if you took your value
0x8ce4b16b
(that would be treating the values you printed above as-if they were a 4-byte double-word in hexadecimal), shifting it by one bit, you would end up with0x19C962D6
.But if you simply want to increment each nibble of your dword (each individual value in a hex-number represents 4-bits or a nibble), you're going to have to add an offset of 0x1 to each nibble. Also there is no value of
G
in a hex-word ... you have the values0->9
, and thenA->F
, whereF
represents the base-10 value 15. Finally, when you add0x1
to0xF
, you're going to wrap around to0x0
.您的意思是要增加字符串中的每个字符吗?
您可以通过迭代数组并向每个字符添加一个来做到这一点。
Do you mean you want to increment each character in the string?
You can do that my iterating through the array and adding one to each character.