delphi - Convert an Octal number to Decimal and Hexadecimal -
i writing program converts octal number decimal , hexadecimal. wrote function called octtoint
.
function octtoint(value: string): longint; var i: integer; int: integer; begin int := 0; := 0 length(value) begin int := int * 8 + strtoint(copy(value, i, 1)); end; result := int; end;
i call function in way:
var oct:integer; begin oct:=octtoint(edit13.text); edit15.text:=inttostr(oct); end;
when type 34
(octal) decimal number should 28 program gives me 220. know why?
also, have idea converter octtohex?
you have change start of "your" for
1.
function octtoint(value: string): longint; var i: integer; int: integer; begin int := 0; := 1 length(value) //here need 1, not 0 begin int := int * 8 + strtoint(copy(value, i, 1)); end; result := int; end;
the conversion octal-hexadecimal hard do, suggest way:
edithexadecimal.text:=(inttohex(strtoint(editinteger.text),8));
as can see here, code edithexadecimal
edit put hexadecimal number. line convert number decimal hexadecimal.
you have decimal number because function octtoint
, don't need more code.
Comments
Post a Comment