0

Hello I want to know how to convert a hexadecimal array to a decimal here's my block

uint8_t block[8] = {0xb,0xb,0xb,0xa,0xa,0xa,0xa,0xa}; here's my code

#include "stdint.h"

void main() {

   uint8_t block[8] = {0xb,0xb,0xb,0xa,0xa,0xa,0xa,0xa};

   uint8_t key[16]  = {0xa,0xa,0xa,0xb,0xb,0xb,0xb,0xb,
                       0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa};

   UART1_Init(9600);  // Initialisation de l’UART1 à 9600 bps
   UART1_Write_Text("message:");
   UART1_Write_Text(block);
   UART1_Write_Text(" TEA Encryption:");
   TEA_Enc(block, key);
   UART1_Write_Text(block);

   UART1_Write_Text("TEA Decryption:");
   TEA_Dec(block, key);
   UART1_Write_Text(block);
} 

For example if i display block i want to have as result like 123456 thank you in advance

11
  • 7
    There is nothing to convert. A number exists in all possible bases simultaneously. Commented Jul 18, 2019 at 20:29
  • hello Eugene Sh do you see block i want to be in decimal if that is possible Commented Jul 18, 2019 at 20:31
  • As I said. It is a bunch of numbers and the numbers are agnostic of the way you are representing them. That is uint8_t block[8] = {0xb,0xb... is exactly the same as uint8_t block[8] = {11,11... Commented Jul 18, 2019 at 20:35
  • You need to clarify your terminology and question. “Hexadecimal” is a notation in which 16 symbols are used to express a number in a base-16 positional numeral system. Commonly the characters “0” to “9” and “A” to “F” (or their lowercase counterparts) are used as the 16 symbols. One could also use the numbers 0 to 15. Your block is an array that contains the numbers 11 and 10. “Decimal” is a notation in which ten symbols are used in a base-10 system. Converting hexadecimal to decimal would result in a numeral made of the digits “0” to “9”. It would not be “hello world”. Those are characters. Commented Jul 18, 2019 at 20:35
  • 1
    Commenters have been trying to say that block is not in hexadecimal, only the way you initialised it. It contains numerica data, and decimal, binary, hexadecimal only make sense in the context of how you print the values for human consumption. Commented Jul 18, 2019 at 20:50

1 Answer 1

3

As Eric and Eugene has said in the comments, there is no way to convert a hexidecimal number to a decimal number. Hexidecimal or decimal only exist in the code you write. Once a compiler sees a number it will store it in memory in it's own representation.

Here's an example of how you can write numbers in different representations in your code. All the numbers I write in the following code are the same. The program does not change, no matter which one you use.

int x = 0x10;
// stored in memory as:
// |0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|

int x = 16;
// stored in memory as:
// |0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|

int x = 0b00000000000000000000000000010000;
// stored in memory as:
// |0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|

int x = 020;
// stored in memory as:
// |0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|

So for your example you block can be represented in either of these ways

uint8_t block_hex[8] = {0xb,0xb,0xb,0xa,0xa,0xa,0xa,0xa};
uint8_t block_dec[8] = {11,11,11,10,10,10,10,10};

Changing between hexidecimal and decimal will not change the behavior of your program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.