You are here

Hex number to base 10 | Cypress Semiconductor

Hex number to base 10

Summary: 6 Replies, Latest post by pnielsen3 on 22 Mar 2013 08:47 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
pnielsen3's picture
User
132 posts

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("      ");      
}

pnielsen3's picture
User
132 posts

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("      ");      
}

H L
user_460349's picture
User
1362 posts

How about LCD_Char_PrintNumber()?

 

pnielsen3's picture
User
132 posts

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

user_1377889's picture
User
10803 posts

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

pnielsen3's picture
User
132 posts

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("      ");  
}

pnielsen3's picture
User
132 posts

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

 

Log in to post new comments.