Article View: comp.lang.pascal.borland
Article #460Re: printing an array to screen ?
From: Ken White
Date: Sat, 12 Sep 1998 00:00
Date: Sat, 12 Sep 1998 00:00
82 lines
2874 bytes
2874 bytes
Michael,
Try this:
function IntToBinString( Number: Word ): String;
var
s : String;
i : Integer;
begin
SetLength( s, 16 );
i := 16;
while i > 0 do
Dec(i, 1);
AppendStr( s, IntToStr((Number shr i) and 1));
end;
Result := s;
end;
procedure ConvDB;
VAR
input: Word;
BEGIN
WRITE ('Enter the decimal to be converted : ');
READLN (input);
WRITELN('Equals to : ' + IntToBinString(input));
end;
Ken
--
Ken White
Clipper Functions for Delphi
http://members.aol.com/clipfunc
Michael Weber wrote:
>
> Need some help !
>
> I am writing a program to convert between number bases.
> In my convDB (decimal to binary) procedure
> I am storing the binary digits n converted at each Iteration in an array
> .
> I want to print it to screen - how ?
> ----------------------------------------------------------------
> PROCEDURE convDB;
> {pre: decimal number is read
> post: binary number printed to screen}
>
> TYPE
> binarry = PACKED ARRAY [0..15] OF INTEGER;
>
> VAR
> input , n : INTEGER;
> element : binarry;
>
> BEGIN
> WRITE ('Enter the decimal to be converted : ');
> READLN (input);
> IF (input < 1) OR (input > 32767) THEN errormsg
> ELSE
> n := 15;
> WHILE input > 1 DO BEGIN
> element[n] := input MOD 2;
> input := input DIV 2;
> n := n - 1;
> END{WHILE};
> element[n] := input;
> WRITE ('Equals to : ',element[0..15]);
> END{convDB};
> --------------------------------------------------------------
> Thanks a lot, I already spent a week on that problem - I know the
> solution is close,
> but I don't get my mistake .
>
> I want to print the whole array at once , NOT through a loop.
>
> Is there any part of my code that can be improved for performance ,
> stability
> etc.. (I am just a student at highschool)
>
> Mike
Technical Details
Message-ID:
<35FADF43.EA59CF01@westelcom.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35F95A97.FA83092A@inode.at>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10261c,5e3ca8698b436352 X-Google-Attributes: gid10261c,public X-Google-Thread: 10baee,5e3ca8698b436352 X-Google-Attributes: gid10baee,public X-Google-Thread: 111659,5e3ca8698b436352 X-Google-Attributes: gid111659,public X-Google-Thread: 14c77f,5e3ca8698b436352 X-Google-Attributes: gid14c77f,public X-Google-Thread: 108ebd,5e3ca8698b436352 X-Google-Attributes: gid108ebd,public From: Ken White <kwhite@westelcom.com> Subject: Re: printing an array to screen ? Date: 1998/09/12 Message-ID: <35FADF43.EA59CF01@westelcom.com> X-Deja-AN: 390511275 Content-Transfer-Encoding: 7bit References: <35F95A97.FA83092A@inode.at> Content-Type: text/plain; charset=us-ascii Organization: Clipper Functions for Delphi MIME-Version: 1.0 Newsgroups: comp.lang.pascal.borland,comp.lang.pascal.misc,borland.public.turbopascal,comp.lang.pascal.delphi.misc,comp.lang.pascal.delphi.comp