Post Reply 
Converting from one base to another?
04-12-2016, 11:07 PM
Post: #14
RE: Converting from one base to another?
Would a subroutine for your application be useful? Perhaps, something like these:

Code:

//  H2D(hex)
//
//  Hexadecimal to Decimal converter
//  Input:  Hexadecimal as quoted string ("09aF") case doesn't matter
//  Output: Decimal equivalent ==> (2479.00)

EXPORT H2D(hex)
BEGIN

  D:=0; N:=SIZE(hex);

  FOR I FROM 1 to N DO    
    D:=D+16^(N-I)*(INSTRING("0123456789ABCDEF", MID(UPPER(hex),I,1))-1);
  END;

  RETURN D;
  
END;

Code:

//  D2H(dec)
//
//  Decimal to Hexadecimal converter
//  INPUT:  Decimal value D2H(666)
//  OUTPUT: Hexadecimal value ==> "29A"

EXPORT D2H(dec)
BEGIN

  local digit,hex:="";

  WHILE 0 < dec DO
    digit:=dec MOD 16;
    dec:= FLOOR(dec/16);
    hex:= append(MID("0123456789ABCDEF",digit+1,1),hex);   
  END;

  RETURN (IFTE(hex=="","0",hex));

END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Converting from one base to another? - smp - 04-09-2016, 10:02 PM
RE: Converting from one base to another? - DrD - 04-12-2016 11:07 PM



User(s) browsing this thread: 1 Guest(s)