-5

I have browsed so many questions regarding converting hexadecimal number to a decimal number but I couldn't find a way to convert a uint_16t hexadecimal number to decimal number.Can you help me in this case?Thanks for any advice.

Pavindu
  • 2,684
  • 6
  • 44
  • 77
  • 1
    What is a "uint_16t hexadecimal number"? How is that different from a regular hexadecimal number? – tadman Nov 02 '18 at 05:00
  • What do you mean, what are the expected inputs, outputs, which questions did not solve your problem, what is a "hexadecimal uint16_t" – Antti Haapala -- Слава Україні Nov 02 '18 at 05:00
  • 1
    An `uint16_t` is neither decimal nor hexadecimal. It is an object with an integer value in the range 0 to (2^16 - 1). How that value is printed to text is controlled by various functions like `printf()` with `%x, %u`, etc. Add more detail to your question to clear identify your goals. Perhaps you want something as simply as _text_with_hexadecimal_characters_ --> `uint16_t` --> _text_with_decimal_characters_? Best to post what you have tried. – chux - Reinstate Monica Nov 02 '18 at 06:43

1 Answers1

2

I assume that for hexadecimal you intend it's value representation, for instance:

uint16_t a = 0xFF;

In this case, you are just telling compiler that the variable a has type unsigned int, and it's value is 0xFF (255). There is no difference between writing

uint16_t a = 0xFF;

And

uint16_t a = 255;

It's value will be the same in both cases. You don't need any conversion. Pay attention to the fact that you are using an unsigned integer of length 16 bits, so the maximum value you can give to the variable before hitting an overflow is 2^16 = 65536

Alex Foglia
  • 520
  • 5
  • 16