不要按位运算符(比其他班)使基10的数学意义吗? [英] Do bitwise operators (other than shifts) make any mathematical sense in base-10?
问题描述
据维基的偏移可用于计算的2的幂:
由n个阿左算术移
相当于由2 ^ N乘以
(提供的值不
溢出),而右算术
由二的补码值的n移位
相当于由2 ^ n和除以
四舍五入向负无穷大。
块引用>我总是想,如果任何其他位运算符(
〜
,|
,&放;
,^
)时,适用于基地10作出任何数学意义?我了解他们的工作,但这种操作的结果可以用于计算任何十进制世界有用吗?解决方案
是的基地-10是我的意思在这种情况下,是的,它们可以被扩展以几种方式至基部10,尽管他们几乎没有二进制一样有用。
一个想法是,
&安培;
,|
等都是一样的做算术MOD-2单个二进制数字。如果A
和B
是单一的二进制位数,然后
A&B = A * B(模2)
一个^ B = A + B(模2)
〜A = 1-α(模2)
A | B =〜(〜A&〜B)= 1 - (1-A)*(1-b)的(模2)在当量碱-10将是的(再次指出,这些是按位应用,而不是整个数)的
A&B = A * B(MOD 10)
一个^ B = A + B(模10)
〜一= 9-A(MOD 10)
A | B =〜(〜A&〜B)= 10 - (9-a)中*(9-b)的(模10)前三设计电路时是有用其中使用 BCD (
〜一个
作为 9的补),如非图形计算器,虽然我们只是使用*
和+
,而不是&安培;
和^写公式时
。首先是也显然是在一些旧密码的。According to wiki shifts can be used to calculate powers of 2:
A left arithmetic shift by n is equivalent to multiplying by 2^n (provided the value does not overflow), while a right arithmetic shift by n of a two's complement value is equivalent to dividing by 2^n and rounding toward negative infinity.
I was always wondering if any other bitwise operators (
~
,|
,&
,^
) make any mathematical sense when applied to base-10? I understand how they work, but do results of such operations can be used to calculate anything useful in decimal world?解决方案"yep base-10 is what I mean"In that case, yes, they can be extended to base-10 in several ways, though they aren't nearly as useful as in binary.
One idea is that
&
,|
, etc. are the same as doing arithmetic mod-2 to the individual binary digits. Ifa
andb
are single binary-digits, thena & b = a * b (mod 2) a ^ b = a + b (mod 2) ~a = 1-a (mod 2) a | b = ~(~a & ~b) = 1 - (1-a)*(1-b) (mod 2)The equivalents in base-10 would be (note again these are applied per-digit, not to the whole number)
a & b = a * b (mod 10) a ^ b = a + b (mod 10) ~a = 9-a (mod 10) a | b = ~(~a & ~b) = 9 - (9-a)*(9-b) (mod 10)The first three are useful when designing circuits which use BCD (
~a
being the 9's complement), such as non-graphing calculators, though we just use*
and+
rather than&
and^
when writing the equations. The first is also apparently used in some old ciphers.这篇关于不要按位运算符(比其他班)使基10的数学意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!