6 Replies Latest reply on Mar 22, 2013 8:47 AM by userc_39236

# Hex number to base 10

How do I convert the hex to a decimal base 0 to 9.

void Display_Result(void)
{

LCD_Char_Position(0,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);         //Mask HYT humidity the highest two status bits
LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
LCD_Char_PrintNumber(unit8,HYT221_Read_Buff);
temp = astio(temp, HYT221_Read_Buff[1], 16);
LCD_Char_PrintString("      ");
LCD_Char_Position(1,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);       //Mask HYT temperature the lowest two status bits
LCD_Char_PrintString("      ");
}

• ###### 1. Re: Hex number to base 10

My original email was wrong. below is the corrected version

void Display_Result(void)
{

LCD_Char_Position(0,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);         //Mask HYT humidity the highest two status bits
LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
LCD_Char_PrintString("      ");
LCD_Char_Position(1,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);       //Mask HYT temperature the lowest two status bits
LCD_Char_PrintString("      ");
}

• ###### 2. Re: Hex number to base 10

How about LCD_Char_PrintNumber()?

• ###### 3. Re: Hex number to base 10

I believe I tried it. I received an email that I needed to use UNIT16. THere is the long and hard way. But I was hoping Kiel software had a function to convert the the number. I have a hex value ex: 3fad. This needs to be converted to a decimal value.

Thanks for the reply.

Philip

• ###### 4. Re: Hex number to base 10

when you #include <stdio.h> you may use sprintf() to convert any number to a string which you may print on LCD.

Parameters for sprintf() are here http://publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html

Bob

• ###### 5. Re: Hex number to base 10

Thanks for the feedback,

My code Is as follows. I get the the hex vale in 4 digits. With the sprintf(0 can I get the complete decimal value?

void Display_Result(void)
{

LCD_Char_Position(0,6);
LCD_Char_PrintInt8(HYT221_Read_Buff[0] & 0x3f);  //Mask HYT humidity the highest two status bits
LCD_Char_PrintInt8(HYT221_Read_Buff[1]);
LCD_Char_PrintString("      ");

///////////////////////////////////////////////////////////
// sprintf()  insert conversion here ?
/////////////////////////////////////////////////////////
LCD_Char_Position(1,6);

LCD_Char_PrintInt8(HYT221_Read_Buff[2]);
LCD_Char_PrintInt8(HYT221_Read_Buff[3] & 0xfc);  //Mask HYT temperature the lowest two status bits
LCD_Char_PrintString("      ");
}

• ###### 6. Re: Hex number to base 10

Bob,

Thanks for the help. My Cypress compiler at work will compile my software fine. But the same software on my home PC will not compile. I am uninstall Creator 2.1 and 2.2 CP5 from my work PC now. Then I will do a clean install? That did not occur to me to check the copilers.

Thanks Bob,

Phi