Shift to the right from the right side using the ALU?

I was wondering if there was an efficient way to perform a right shift on an 8-bit binary value using only ALU operators (NOT, OR, AND, XOR, ADD, SUB)

Example:

input:  00110101
output: 10011010

I managed to implement a left shift by simply adding an 8-bit binary value with me, since a left shift is equivalent to multiplying by 2. However, I cannot think of a way to do this to switch correctly.

The only method I came across is to simply perform 7 left trunk shifts. Is this the only way?

+3
source share
1 answer

, {AND, OR, XOR, NOT}. outbit [N] inbit1 [N] inbit2 [N] . inbit1 [N].. inbit1 [0] inbit2 [N].. inbit2 [0]. inbit [N + 1]. , , - , SUB.

A - B A + (-B), A + ((B XOR 11111111) +1). , SUB, ADD XOR. , . , {ADD, OR, XOR, NOT, ADD, SUB} .

+2

Source: https://habr.com/ru/post/1719857/


All Articles