2
$\begingroup$

Is there a way to represent binary operation in decimal. What I mean with this is for example a set of decimal operators that would give the same result as a x>>n a ror(x), etc. So far the only thing I reached is that $\ x>>1_{2}$ would be a $\sqrt x_{10}$ and the reverse $\ x<<1_{2}$ is $\ x^2_{10}$

EDIT:

Not sure but I would venture to say that a ROR operation would be something like $\mod(\sqrt x_{10}, 2^n)$ where n is the number of bits of the binary representation.

$\endgroup$
0
$\begingroup$

Shifting number $x$ right gives you $x/2$ (rounded down) and left - $2x$.
In case of ROR (I believe you meant a circular shift) you have the following: $$ x>>1 = \begin{cases} x/2 & \text{if } x_{10} = 2k \\ x/2 + 2^{N-1} & \text{if } x_{10} = 2k +1 \end{cases} $$ $$ x<<1 = \begin{cases} 2x & \text{if } x_{10} < 2^{N-1} \\ 2(x -2^{N-1}) + 1 & \text{if } x_{10} \geq 2^{N-1} \end{cases} $$

Where $n$ is a bit lenght of $x$. You may simple get $x>>n$ and $x<<n$, $\forall n \in \mathbb N$ from here.

$\endgroup$
  • $\begingroup$ Thank you this is the kind of answer I was looking for but I was looking for all binary operations(and, not, or, xor, etc...). I just gave >> and ror (circular shift right) as examples of operations. Maybe there is some sort of cheatsheet for this kind of thing. $\endgroup$ – Leonardo Marques Oct 9 '14 at 11:38
  • $\begingroup$ Not sure these functions would have a good, useful representation, as bitwise AND or XOR work with single bits, so you couldn't avoid converting number from DEC to BIN (or present your number as a sum of $a_i2^i$, $i = 0, 1, ... , N-1$ which is virtually the same as converting from DEC to BIN). $\endgroup$ – Andrei Rykhalski Oct 9 '14 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.