This message was edited by DirtyK at 2004-12-1 14:43:54
: : Yes I'm here again...
: : I need to write a procedure to input a decimal number via a suitable const parameter and output the hexadecimal equivalent to the console window...
: : Now, I can do the maths and figure I need to use a loop of some type, but can anyone help me on how i can store the numbers separately within the loop to put together at the end of the procedure...?
: : For example... you need to mod the number by 16 to get the remainder and then div by 16 and repeat with new num... how do you store the remainders and convert them into the hex equivalent without having lines and lines of code?
: : Any advice would be appreciated... As I've said before I am pretty new to this and really wanna learn the language...
: here is a sample code:
: i: integer;
: Number: integer;
: HexValue: string;
: HexStr := '';
: while Number > 0 do
: HexStr := HexValues[Number mod 16+1] + HexStr;
: Number := Number div 16+1
: I'm not sure if the resulting hex string will be inverted or not. The code should be easy enough to follow and understand.
I have this code now does this seem fairly right?
Whereabouts and how do I read in the hex values...? And if this code isn't looking right... can you give me a pointer as to where am i going wrong?
user : integer;
procedure DecToHex (Number : integer);
Hexstr, prop : string;
HexStr := '';
while Number > 0 do
HexStr := HexValue[Number mod 16+1] + HexStr;
Number := Number div 16+1
writeln (' enter a number');