On 01/12/2005 the venerable Jim Thompson etched in runes:
Not neccessarily, because that requires access to the carry bit which has been shifted out. My method only looks at the contents of the register and thus can be done in a high level language such as 'C' which has no knowledge of the carry bit.
Yes... and I think the original poster has that luxury, I concur that this looks a lot like homework. So what he's needing to do is draw a K-map. I just wanted to steer him in the right direction without doing it for him
By the way, code to draw K-maps is not too hard to write. Collecting minterms isn't too far beyond that. Reducing 'em isn't too far beyond that. Having tools like that cuts the time down, bringing such luxuries into reach of even the humble compiler user
I can still do 'em by hand but, now-a-days, I use KarnaughMap v4.4.5, by Russell Sasamori...
formatting link
...Jim Thompson
--
| James E.Thompson, P.E. | mens |
| Analog Innovations, Inc. | et |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems | manus |
| Phoenix, Arizona Voice:(480)460-2350 | |
| E-mail Address at Website Fax:(480)460-2142 | Brass Rat |
| http://www.analog-innovations.com | 1962 |
I love to cook with wine. Sometimes I even put it in the food.
A lookup table is the fastest way to do this, and most other bit counting/swapping/noticing/priority kinds of things, if you have the memory.
--- Regards, Bob Monsen
The question of the ultimate foundations and the ultimate meaning of mathematics remains open; we do not know in what direction it will find its final solution or even whether a final objective answer can be expected at all. "Mathematizing" may well be a creative activity of man, like language or music, of primary originality, whose historical decisions defy complete objective rationalization.
Yes. I saw a mension of counting the total number of bits elsewhere. I guess I didn't pay careful enough attention to which I was responding to.
It should be:
TEMP := X; Y := 0;
if (TEMP and $F0) = 0 then begin TEMP := TEMP shl 4; Y := Y + 4; end;
if (TEMP and $C0) = 0 then begin TEMP := TEMP shl 2; Y := Y + 2; end;
if (TEMP and $80) = 0 then begin TEMP := TEMP shl 1; Y := Y + 1; end; With a little work this could be reduced to a loop. Note that you get a normalized output as well as the shifts needed to normalize.
Assuming a math co-processor on the system, by far the simplest, fastest, and most obtuse way is to convert to floating point and figure out what to do with the exponent. (IEEE floating point values are stored as a mantissa between .5 and 1 raised to an exponent of 2.)
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.