I'm trying to figure out how to implement a bit counter in LC3 assembly language. ex: input "00001100001000001" output "000000000000100" I would be counting the number of ones in the string of bits and outputting that number in binary. I know how to do this given one bit at a time, but I don't know how I can analyze only one bit of a 16 bit string at a time. Thanks.
相关问题
- Index of single bit in long integer (in C) [duplic
- Cast some light on population count algorithm
- Is BIT field faster than int field in SQL Server?
- Combine 2 numbers in a byte
- Moving a bit within a byte using bitfield or bitwi
相关文章
- How does Java calculate negative numbers?
- Fastest way to count consecutive 1 bits. C++
- why endianess matters among bits inside a byte?
- Hamming distance between two binary strings not wo
- n is negative, positive or zero? return 1, 2, or 4
- Python - Decimal to Hex, Reverse byte order, Hex t
- Can a public key have a different length (encrypti
- Bit manipulations good practices
There are several different ways you can count the number of bits in a value stored in the LC3.
Personally, I would use the bit mask method because it's quick and efficient, and I won't have to worry about bogging my code down.
A bit mask looks like the following:
Now all you have to do is create a loop that AND's each of these mask values with your stored value. If you get a positive number after ANDing them then you would just add 1 to your bit counter, and then repeat the process with each of the remaining mask values.