View Single Post
  #1  
Old 8th December 2008, 16:13
george7a's Avatar
george7a george7a is offline
Guru
 
Join Date: May 2004
Location: Nazareth
Posts: 1,490
george7a is on a distinguished road
Baan: IVc, 5.0 b, 5.0 c, LN 6.1 - DB: MS SQL, Oracle - OS: Windows 2000, 2003 & UNIX
Hexadecimal, Decimal & Binary Conversion Functions

Hi,

I wrote some conversion functions and I thought I will share them.

Dec.to.Hex takes a decimal number and returns hexadecimal in a string
Code:
function domain tcmcs.str300m Dec.to.Hex(long dec.num)
{
   | Written By: George Abdo
   domain tcmcs.str300m res.hex
   
     
   if dec.num = 0 then return("0") endif
   
   res.hex = ""
   while dec.num <> 0 

      res.hex = Dec.to.Hex.digit(dec.num\16) & res.hex  | mod
      dec.num = dec.num /16 | div
      
   endwhile
   return (res.hex)

}

| This function is used only to convert one digit.

function domain tcmcs.str1 Dec.to.Hex.digit(long dec.num)
{
   | Written By: George Abdo
   string res.hex(1)
   
   on case dec.num
   
      case 10: res.hex = "A"
         break
      case 11: res.hex = "B"
         break
      case 12: res.hex = "C"
         break
      case 13: res.hex = "D"  
         break         
      case 14: res.hex = "E"
         break
      case 15: res.hex = "F"
         break
      default: res.hex = str$(dec.num)
         break
   endcase    

   return(res.hex)
}
__________________
_
George Abdo
NAZDAQ - Your Documents, Your Way.
Reply With Quote