Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

decimal to hex and hex to decimal conversion in ccs pic compiler.

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
208
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,763
hi
i simply need to convert decimal (8 bit) to hex in CCS. In mikroC, that is so easy to convert by using "bcd2dec" built in function. but in CCS i think there is no any function like that so how can i do?
 

Code:
unsigned char DecToBCD (unsigned char Value)
{
  return ((Value / 10) << 4) | (Value % 10);
}

unsigned char BcdToDec (unsigned char Value)
{
  return ((Value >> 4) * 10) + (Value & 0x0F);
}
 
The code is right for BCD conversion and should be equivalent to the respective MikroC built-in functions. Hex conversion as asked in the question title is a different thing.
 

How can I help if I can't understand what does he means?
HEX to string conversion?
Code:
void ValueToStringHEX_Byte (unsigned char Value, char * String)
{
   const unsigned char HEX_Var[17]={"0123456789ABCDEF"};
   * String++ =   ((Value&0xF0)>>4)[HEX_Var];
   * String   =    (Value&0x0F)[HEX_Var];
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top