One position right barrel shift using ALU Operators?

Filed under:
|
|
|
bitwise-operations

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

``````Example:

input:  00110101
output: 10011010
``````

I have been able to implement a shift left by just adding the 8 bit binary value with itself since a shift left is equivalent to multiplying by 2. However, I can't think of a way to do this for shift right.

The only method I have come up with so far is to just perform 7 left barrel shifts. Is this the only way?

© Stack Overflow or respective owner

• Java bitshift strangeness

as seen on Stack Overflow - Search for 'Stack Overflow'
Java has 2 bitshift operators for right shifts: >> shifts right, and is dependant on the sign bit for the sign of the result >>> shifts right and shifts a zero into leftmost bits http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op3.html This seems fairly simple, so can… >>> More

• Bit shift and pointer oddities in C, looking for explanations

as seen on Stack Overflow - Search for 'Stack Overflow'
Hi all, I discovered something odd that I can't explain. If someone here can see what or why this is happening I'd like to know. What I'm doing is taking an unsigned short containing 12 bits aligned high like this: 1111 1111 1111 0000 I then want to shif the bits so that each byte in the short hold… >>> More

• Bitshift in javascript

as seen on Stack Overflow - Search for 'Stack Overflow'
I've got a really big number: 5799218898. And want to shift it right to 13 bits. So, windows-calculator or python gives me: 5799218898 13 | 100010100100001110011111100001 13 70791 | 10001010010000111 As expected. But Javascript: 5799218898 13 | 100010100100001110011111100001 … >>> More

• Learning about C Bitshift Operators

as seen on ASP.net Weblogs - Search for 'ASP.net Weblogs'
So I was doing some reading tonight on my Nerdkit , I had planned to actually do some playing around with it, but decided just to read a bit. I’ve never coded in C, I did C++ in College (not very well) and do most of my development in C# these days (when I’m doing code, mostly for fun). While all… >>> More

• Implementing a bit shift using AND, NOT, ADD [closed]

as seen on Programmers - Search for 'Programmers'
I'm implementing a 16-bit left bit shift by r bits, and I only have access to AND, NOT and ADD. There are 3 condition codes, negative, zero and positive, which are set when you use any of these operations. How I went about it was : (1) And the number with 1000 0000 0000 0000 to set condition codes… >>> More

• How do boost operators work?

as seen on Stack Overflow - Search for 'Stack Overflow'
boost::operators automatically defines operators like + based on manual implementations like += which is very useful. To generate those operators for T, one inherits from boost::operators<T> as shown by the boost example: class MyInt : boost::operators<MyInt> I am familiar with the CRTP… >>> More

• Use Comparison Operators in SQL to Remove/Return Columns with Null Values

as seen on Internet.com - Search for 'Internet.com'
When you use the comparison operators in SQL with the Where clause, you can remove the columns with null values. >>> More

• Use Comparison Operators in SQL to Remove/Return Columns with Null Values

as seen on Internet.com - Search for 'Internet.com'
When you use the comparison operators in SQL with the Where clause, you can remove the columns with null values. >>> More

• How do I overload an operator for an enumeration in C#?

as seen on Stack Overflow - Search for 'Stack Overflow'
I have an enumerated type that I would like to define the , <, =, and <= operators for. I know that these operators are implictly created on the basis of the enumerated type (as per the documentation) but I would like to explictly define these operators (for clarity, for control, to know how… >>> More

• Which are the fundamental stack manipulation operations?

as seen on Programmers - Search for 'Programmers'
I'm creating a stack oriented virtual machine, and so I started learning Forth for a general understanding about how it would work. Then I shortlisted the essential stack manipulation operations I would need to implement in my virtual machine: drop ( a -- ) dup ( a -- a a ) swap ( a b -- b a ) rot… >>> More