Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,可以说“123|ABC|test|12345|FF”,我想对每个字符的 ascii 值进行异或运算并以十六进制打印结果。
最简单的方法是什么?
找到了...
lrc = 0 input.each_byte do | c | lrc ^= c end hexVal = lrc.to_s(16)
在 Ruby 1.8.7 或 1.9.1 中:
input.bytes.inject { |a,b| a ^ b }.to_s(16)