Question and Answer Database FAQ2834D.txt Covert string of (zeros and ones) to binary. Category :Object Pascal Platform :All Product :All 32 bit Question: How can I convert a string of zeros and ones to the integer it represents? Answer: The following example shows how to convert a "BinaryString" to a long integer by using the shl (shift bits left) macro. Example: function BinStringToLongInt(BinString : string) : longint; var i : integer; Num : longint; begin Num := 0; for i := 1 to length(BinString) do if BinString[i] = '1' then Num := (Num shl 1) + 1 else Num := (Num shl 1); Result := Num; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Add(IntToStr(BinStringToLongInt('11111111'))); end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99