Today, I would like to present you an original way of iterating thru all the bits in an integer. http://francois-piette.blogspot.com/2013/01/original-method-to-iterate-bits-within.html
Today, I would like to present you an original way of iterating thru all the bits in an integer. http://francois-piette.blogspot.com/2013/01/original-method-to-iterate-bits-within.html
http://francois-piette.blogspot.com/2013/01/original-method-to-iterate-bits-within.html
http://francois-piette.blogspot.com/2013/01/original-method-to-iterate-bits-within.html
Good post, François, that makes code simpler and concise! Iterator as an design pattern with compiler support (for..in statement) is really a cozy thing in Delphi .
ReplyDeleteDenys Almaral why so complicated? write((value shr i) and 1); produces the same ouput;
ReplyDeletefor 32-bit integers there is TIntegerSet type, we can get the same output using the next code:
intSet := TIntegerSet(value);
for b in [0..31] do begin
write(ord(b in intSet));
end;
Denys Almaral Well, it is not complicated at all. But anyway, as any other abstraction, the goal is to write code once which makes things easier and more readable, understandable later. Beside the abstraction, as stated in the article, the aim is also the help people understand what they can do with enumerator and how to do it. They will produce better code.
ReplyDelete