You are here: Home FORUM Support Decimal to Hex Formatting Issue

nqBASIC

  :: Support
Welcome Guest   [Register]  [Login]
 Subject :Decimal to Hex Formatting Issue.. 02-08-2010 16:28:54 
ajbeal
Joined: 01-11-2009 11:18:04
Posts: 20
Location: Knoxville, TN USA

I am trying to have nqBasic add the hex '0x' prefix to a 2-digit decimal number, without changing the two original 2 digit number. This is for use with a SPI driven 7-segment LED decoder driver (MC14489). The decimal number must always be 2-digits and range from 00 to 99 inclusive. Example1: decimal = 00, hex = 0x00. Example2: decimal = 12, hex = 0x12. Example3: decimal = 99, hex = 0x99. This may seem strange, but the MC14489 needs this particular formatting for its data. I'm unsure how to do it, other than having 100 case statements, one for each possible decimal value between 00 and 99.

IP Logged
 Subject :Re:Decimal to Hex Formatting Issue.. 05-08-2010 03:41:32 
ajbeal
Joined: 01-11-2009 11:18:04
Posts: 20
Location: Knoxville, TN USA
I think I can make this work if I had a Decimal-to-Hex conversion routine for nqBasic. Does anyone have one, or know the basic code for such???
IP Logged
 Subject :Re:Decimal to Hex Formatting Issue.. 28-12-2011 06:50:45 
LouB
Joined: 27-12-2011 21:28:46
Posts: 2
Location
For your examples above to convert decimal to hex string I did this only using 16 case lookups with a number = x that is between 0 and 255 y = int (x/16) if y > 0 firstchar = sub lookup(int(y)) x = x - 16*y else firstchar = "0" endif secondchar = sub loolup(x) sub lookup(i) case 0 return 0 1 return 1 2 return 2 ...... 10 return A 11 return B .... 15 return F end select end sub
IP Logged
 Subject :Re:Decimal to Hex Formatting Issue.. 04-01-2012 19:33:40 
melodyfred
Joined: 05-01-2012 00:30:17
Posts: 1
Location: Windsor
The above basic code example given can work for you..!!
IP Logged
business mobile phones
Page # 


Powered by ccBoard