Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IntToOctal

0 views
Skip to first unread message

Guillermo Sanchez

unread,
Jun 26, 2002, 3:57:31 PM6/26/02
to
If not, can some of you give me a hint, to create one?
"Guillermo Sanchez" <guillerm...@codetel.com.do> wrote in message
news:3d1a1c49_2@dnews...
> I need to know if there is a function in D6 to convert an integer value
from
> decimal to octal?
> Best regards,
> Guillermo
>
>


Guillermo Sanchez

unread,
Jun 26, 2002, 3:55:53 PM6/26/02
to

Vikram Kulkarni

unread,
Jun 26, 2002, 4:04:42 PM6/26/02
to
Try this :

function AsOctal(i : integer) : string;

var

Digit : byte;

begin

while (i > 0) do

begin

Digit := (i AND 7); // This is a bitwize AND, meaning:

// 001001010011010 (Some number)

// AND 000000000000111 ( 7 )

// ---------------

// 000000000000010 ( 2 )

{ convert this digit to Octal }

i := (i shr 3); // this "shifts" the number right 3 bits:

// 001001010011010 (Some number)

// becomes 000001001010011 (Some number DIV 8)

end;

end;

OR

procedure TForm1.Button1Click(Sender: TObject);

var

c : char;

i : integer;

begin

c := 'b'; {or any character}

i := ord(c);

edit1.text := IntToStr((i shr 6) and 7) + IntToStr((i shr 3) and 7) +
IntToStr(i and 7);

end;

Result is '142' octal (=98 decimal).

I have not tried but it should work.

"Guillermo Sanchez" <guillerm...@codetel.com.do> wrote in message

news:3d1a1cab_1@dnews...

Mauro Patiño

unread,
Jun 26, 2002, 4:23:18 PM6/26/02
to
Guillermo Sanchez wrote:

This appears to work.

procedure TForm1.Button1Click(Sender: TObject);
var
Decimal: integer;
Remainder: integer;
Fit: integer;
begin
Decimal := 10;
Fit := Decimal;
repeat
Remainder := Fit mod 8; {change 8 to 2 for binary,etc.}
Fit := Fit div 8;
Memo1.Lines.Add(IntToStr(Remainder));
until Fit = 0;
end;


Guillermo Sanchez

unread,
Jul 1, 2002, 11:29:47 AM7/1/02
to
Mauro:
Thanks A LOT! It worked.
Vikram, thank you also.
Best regards,
Guillermo
"Mauro Patiño" <M-Pa...@govst.edu> wrote in message
news:3D1A22B6...@govst.edu...
0 new messages