From: "Bruce Roberts" Subject: Re: How to reverse the bits in a integer? Date: 13 Mar 2000 00:00:00 GMT Message-ID: References: <8al9dn$oj2$1@newton.pacific.net.sg> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@netcom.ca X-Trace: tor-nn1.netcom.ca 953056842 142.194.174.198 (Tue, 14 Mar 2000 13:00:42 EDT) Organization: Roberts Browne Limited X-MSMail-Priority: Normal Reply-To: "Bruce Roberts" NNTP-Posting-Date: Tue, 14 Mar 2000 13:00:42 EDT Newsgroups: comp.lang.pascal.delphi.misc "Tan Tze Yong" wrote in message news:8al9dn$oj2$1@newton.pacific.net.sg... > Dear fellow Delphi programmers, > Is it possible to reverse the bits in a integer, i.e. move the most > significant bit to the front? Any help will be appreciated. Below is a function that will reverse the bits of an integer. function ReverseBits (anInt : integer) : integer; var i : integer; begin result := 0; for i := 0 to (SizeOf (anInt * 8) - 1) do begin result := (result shl 1) or (anInt and $01); anInt := anInt shr 1; end; end;