# Thread: Converting dec to hex, no built-in support?

1. ## Converting dec to hex, no built-in support?

I need to convert decimal value to hex, to send it to RTC. Seems like PBP has no built in convertors?

I have hex values such as rtcmin, rtcsec, rtchour and so on.
I have a decimal variable which changes on button press. Have to convert it to hex, but can't find proper statement.
Of course I can do it by hand, like this

Code:
```IF TIMEVAR=10 THEN RTCMIN=\$10
IF TIMEVAR=11 THEN RTCMIN=\$11```
and so on, but just to set minutes, I will need 60 lines of code!

Why statements like RTCMIN=HEX TIMEVAR or RTCMIN=\$TIMEVAR do not work?

2. ## Re: Converting dec to hex, no built-in support?

You will find everything you would need for DS1302 there.

3. ## Re: Converting dec to hex, no built-in support?

Well that was just an example. There are many cases when it's need to convert from DEC to HEX...

4. ## Re: Converting dec to hex, no built-in support?

I'm adding this here, so it can be found using search by someone else when needed.

The code below was borrowed from DS1302 thread and converts decimal to hex.

Code:
```'RTC - target variable in hex
'decx - source variable in dec
RTC=decx DIG 1
RTC=RTC<<4
RTC=RTC+decx DIG 0```

5. ## Re: Converting dec to hex, no built-in support?

The code below was borrowed from DS1302 thread and converts decimal to hex.
hope nobody actually believes this

the code actually converts a binary value between 0 and 99 to packed bcd , its not hex

6. ## Re: Converting dec to hex, no built-in support?

great
at least it works with DS1302