+ Reply to Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    546

    Default 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. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: Converting dec to hex, no built-in support?

    http://www.picbasic.co.uk/forum/showthread.php?t=423

    You will find everything you would need for DS1302 there.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Feb 2013
    Posts
    546

    Default 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. #4
    Join Date
    Feb 2013
    Posts
    546

    Default 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. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default 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
    This is more entertaining than Free to Air TV

  6. #6
    Join Date
    Feb 2013
    Posts
    546

    Default Re: Converting dec to hex, no built-in support?

    great
    at least it works with DS1302

Similar Threads

  1. hex dec ascii
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th February 2015, 21:11
  2. HSERIN/OUT Dec to HEX convertion problem..
    By N6VMO_ in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th July 2010, 21:48
  3. Converting Dec word to Hex string
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th August 2007, 05:44
  4. Convert dec/binary to Hex
    By SagemFree in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th May 2005, 18:00
  5. Converting Bytes from hex to Dec
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th April 2005, 19:44

Members who have read this thread : 26

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts