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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -