一个字节数组的高效二进制补码 [英] efficient two's complement of a byte array
问题描述
计算可变长度字节数组的两个补码
的最有效方法是什么?
感谢您的时间。
What would be the most efficient way to calculate the two''s complement
of a variable length byte array?
Thanks for your time.
推荐答案
da ***** **** @gmail.com 写道:
什么是计算两个补码的最有效方法
的可变长度字节数组?
What would be the most efficient way to calculate the two''s complement
of a variable length byte array?
我会假设一个for循环否定就足够了
用于大多数目的。
你可以尝试否定int或者长期使用不安全的代码和
a指针。
Arne
I would assume a for loop negating would be good enough
for most purposes.
You could try negating int or long using unsafe code and
a pointer.
Arne
2月10日下午12:05,Arne Vajh?j< a ... @ vajhoej.dkwrote:
On Feb 10, 12:05 pm, Arne Vajh?j <a...@vajhoej.dkwrote:
darthgha ... @ gmail.com写道:
darthgha...@gmail.com wrote:
计算可变长度字节数组的两个补码
的最有效方法是什么?
What would be the most efficient way to calculate the two''s complement
of a variable length byte array?
我会假设一个for循环否定就足够了
用于大多数目的。
你可以尝试否定int或者长期使用不安全的代码和
a指针。
Arne
I would assume a for loop negating would be good enough
for most purposes.
You could try negating int or long using unsafe code and
a pointer.
Arne
我不能否定int或long,因为数字可能超过40亿
位数(十六进制)。 for循环可以解决这个问题,但我希望有人可能知道不同的方式。谢谢你的想法
虽然。
克里斯
I can''t negate int or long because the number could be over 4 billion
digits (in hex). A for loop would do the trick, but I was hoping
someone might know of a different way. Thanks for the thoughts
though.
Chris
2月12日,下午2:54 ,darthgha ... @ gmail.com写道:
On Feb 12, 2:54 pm, darthgha...@gmail.com wrote:
2月10日下午12:05,Arne Vajh?j< a ... @ vajhoej.dkwrote :
On Feb 10, 12:05 pm, Arne Vajh?j <a...@vajhoej.dkwrote:
darthgha ... @ gmail.com写道:
darthgha...@gmail.com wrote:
什么是最有效的方式计算一个可变长度字节数组的两个补码
?
What would be the most efficient way to calculate the two''s complement
of a variable length byte array?
我会假设一个for循环否定就足够了
用于大多数目的。
I would assume a for loop negating would be good enough
for most purposes.
您可以尝试使用不安全的代码来否定int或者长期使用
指针。
You could try negating int or long using unsafe code and
a pointer.
Arne
Arne
我不能否定int或long因为数字可以超过40亿
位数(十六进制)。 for循环可以解决这个问题,但我希望有人可能知道不同的方式。谢谢你的想法
虽然。
I can''t negate int or long because the number could be over 4 billion
digits (in hex). A for loop would do the trick, but I was hoping
someone might know of a different way. Thanks for the thoughts
though.
Arne建议的是一个古老的C技巧:循环遍历数组
一次一个长(64位),否定每个很长一段时间,而不是这样做。
a字节一次。但是,正如他所指出的那样,你必须使用
不安全代码才能做到这一点。
What Arne was suggesting was an old C trick: looping over the array
one long (64 bits) at a time, negating each long, rather than doing it
a byte at a time. However, as he pointed out, you would have to use
unsafe code to do this.
这篇关于一个字节数组的高效二进制补码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!