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
210
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,774
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?
 

Easyrider83

Advanced Member level 5
Joined
Oct 11, 2011
Messages
1,608
Helped
374
Reputation
748
Reaction score
362
Trophy points
1,363
Location
Tallinn, Estonia
Activity points
8,577
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);
}
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,138
Helped
14,381
Reputation
29,026
Reaction score
13,135
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,236
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.
 

Easyrider83

Advanced Member level 5
Joined
Oct 11, 2011
Messages
1,608
Helped
374
Reputation
748
Reaction score
362
Trophy points
1,363
Location
Tallinn, Estonia
Activity points
8,577
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top