User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 426,791 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,762 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 30823 | Replies: 2
Reply
Join Date: Dec 2004
Posts: 1
Reputation: dirtyk is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dirtyk dirtyk is offline Offline
Newbie Poster

Help Converting Dec to Hex without using IntToHex...

  #1  
Dec 1st, 2004
Hi I am quite a new programmer and I was just wondering if there's anyone out there who could help me...

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 cumbers separately to put together at the end of the procedure...?
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 207
Reputation: Real-tiner is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 7
Real-tiner Real-tiner is offline Offline
Posting Whiz in Training

Re: Converting Dec to Hex without using IntToHex...

  #2  
Jan 18th, 2005
I wrote one years ago where I stored the hex digits in a string.
Reply With Quote  
Join Date: Jan 2005
Posts: 31
Reputation: Jackrabbit is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Jackrabbit Jackrabbit is offline Offline
Light Poster

Re: Converting Dec to Hex without using IntToHex...

  #3  
Feb 2nd, 2005
program dec2hex;

{$APPTYPE CONSOLE}

uses
  SysUtils;

const
   BASE16 = 16;
var
   HexValue  : string;
   Remainder : Integer;
   Quotient  : Integer;
begin
   HexValue := '';
   write( 'Enter an integer value: ' );
   readln( Quotient );
   while Quotient > 0 do
   begin
      Remainder := Quotient mod BASE16;
      case Remainder of
         10: HexValue := 'A' + HexValue;
         11: HexValue := 'B' + HexValue;
         12: HexValue := 'C' + HexValue;
         13: HexValue := 'D' + HexValue;
         14: HexValue := 'E' + HexValue;
         15: HexValue := 'F' + HexValue;
      else
         HexValue := IntToStr( Remainder ) + HexValue;
      end;
      Quotient := Quotient div BASE16
   end;
   writeln;
   writeln( HexValue );
   writeln;
end.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 7:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC