在这个 Ruby on Rails 助手中,有以下方法:
# Convert an 8-bit or 16-bit string to an array of big-endian words
# In 8-bit function, characters >255 have their hi-byte silently ignored.
def str2binb(str)
bin = []
mask = (1 << $chrsz) - 1
#for(var i = 0; i < str.length * $chrsz; i += $chrsz)
i = 0
while(i < str.length * $chrsz)
bin[i>>5] ||= 0
p 'i'
p i
p '$chrsz'
p $chrsz
p 'str[i / $chrsz]'
p str[i / $chrsz]
p 'mask'
p mask
bin[i>>5] |= (str[i / $chrsz] & mask) << (32 - $chrsz - i%32)
i += $chrsz
end
return bin
end
运行时,出现此错误就bin[i>>5] |= (str[i / $chrsz] & mask) << (32 - $chrsz - i%32)
行了:
ActionView::Template::Error (undefined method `&' for "J":String)
我不明白&
在这种情况下如何使用。如何解决此错误?我正在使用 Rails 3.2.0 和 Ruby 1.9.2。
这是日志记录输出:
"i"
0
"$chrsz"
8
"str[i / $chrsz]"
"J"
"mask"
255