hi,
how to change the value of hex to decimal
For example from hex "0x15" to decimal 15 or in hex like 0x0f.
do we have any option in keil or any other way.
Thankyou
arun.
The problem with the above code is that we don't know if the OP know what BCD is. Was 0x15 -> 15 attempted to be a BCD to decimal conversion or an accidental evaluation error?
We constanly suffer from people that don't want to describe what problem they have. They first want to make a couple of own assumptions and then asks a half-mashed question that can't be answered because of lack of information, and often shouldn't even be answered since it is based on the OP being half-way down the wrong path.
If BCD was intended, then the next thing is if there is a need for error recovery - is there a chance that the above function may be called with an invalid BCD value that must be correctly detected? 0xff -> 165 wouldn't be so fun, but isn't a problem if there is screening of the values earlier in the process.
We constanly suffer from people that don't want to describe what problem they have.
I think suffering is the wrong word. To me it's fun :-)
For example, see my posts of 15-Jun-2011 12:52 GMT and 13:40 GMT in this thread: http://www.keil.com/forum/19091/
There seems to be a fundamental problem in distinguishing between a requirement (or "goal"), and an attempted solution to that requirement.
www.catb.org/.../smart-questions.html
First sorry if i irritated you all.
I know how to convert hex "0x15" to decimal 21.
I am using a RTC DS1307 with 89s52 and displaying time in LCD.
have to write and read in hex only with the RTC.
I can write and read the values in RTC and also displayed it in LCD.
The problem for me is when i try to edit the time.
I receiving it in hex and if i directly send it to LCD and edit, the value after 09 became some other characters. if i convert it to decimal and send to LCD it works.
But in the first place itself, if i read 0x15 it displays 21 because i converting it to decimal.
That's why i need to change the hex '0x15' to decimal 15 not 21.
I think you may understand my problem. if not again sorry.
i thought keil will have some option for this, like the typecast.
In other words, you are using BCD or Binary-Coded Decimal - or, strictly, packed BCD.
In packed BCD, each nibble of the binary data holds one digit of the decimal value.
So, all you need to do is to extract the individual nibble values, and display them as the digit values.
You can extract the individual nibble values by using the standard 'C' shift & mask bitwise operators.
This really is a very common task indeed - you should easily be able to find plenty of examples...