convert decimal to hexa and stored it in TIMER

How to convert the decimal value to hexadecimal value which needed to be stored in the timer? for example: Timer Low and Timer High only need 2 values such as the 0xFB. How can we extract it if we able to get the hexa from decimal? Have any ideas abt this ? thanx

Parents
  • Think more carefully - there is no conversion required here.
    A 16-bit number is the same number whether you choose to display it in binary, decimal, hexadecimal, or any other radix (number base)!
    You could even display it using Roman numerals, if you want!

    So the question is just how to separate the individual bytes - this is a standard 'C' problem, and nothing specifically to do with Keil.

    To be completely portable & compiler independent, use the standard 'C' shift and mask (bitwise-AND) operators;
    To be possibly quicker and use less code, use a union or pointers.

    It's all been discussed many times before - try a search...

Reply
  • Think more carefully - there is no conversion required here.
    A 16-bit number is the same number whether you choose to display it in binary, decimal, hexadecimal, or any other radix (number base)!
    You could even display it using Roman numerals, if you want!

    So the question is just how to separate the individual bytes - this is a standard 'C' problem, and nothing specifically to do with Keil.

    To be completely portable & compiler independent, use the standard 'C' shift and mask (bitwise-AND) operators;
    To be possibly quicker and use less code, use a union or pointers.

    It's all been discussed many times before - try a search...

Children
More questions in this forum