Reply by old_cow_yellow August 18, 20072007-08-18
--- In m..., "David Collier"
wrote:
>
> >
> > dig1= (value & 0XF000)/0X1000; //isolate dig 1//
>
> Nothing like that will work.
>
> the hexadecimal value bears no relation to the decimal one, and the only
> way to extract the decimal is to make the transistors sweat.
>
> My method will eliminate divides, ( which take forever on an MSP430
), if
> you care about such things.
> But it occupies lots of program space. Which may not bother you :-)
>
> David
>

For people with 16 fingers, they have to convert to hexadecimal digits
before they can count.

Beginning Microcontrollers with the MSP430

Reply by alex ander August 17, 20072007-08-17
Hello David,
The statement below worked fine to separate hex bytes from ADC and it did
separate hex numbers but not the decimal....The issue i was facing was that
i was not knowing compiler well enough for those stunts :).....For e.g for
input of 0X5ACD.... below statement would store 0x0005 in dig1 during run time

David Collier wrote:
>
> dig1= (value & 0XF000)/0X1000; //isolate dig 1//

Nothing like that will work.

the hexadecimal value bears no relation to the decimal one, and the only
way to extract the decimal is to make the transistors sweat.

My method will eliminate divides, ( which take forever on an MSP430 ), if
you care about such things.
But it occupies lots of program space. Which may not bother you :-)

David

---------------------------------
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us.
Reply by David Collier August 17, 20072007-08-17
>
> dig1= (value & 0XF000)/0X1000; //isolate dig 1//

Nothing like that will work.

the hexadecimal value bears no relation to the decimal one, and the only
way to extract the decimal is to make the transistors sweat.

My method will eliminate divides, ( which take forever on an MSP430 ), if
you care about such things.
But it occupies lots of program space. Which may not bother you :-)

David
Reply by Microbit August 11, 20072007-08-11
Hi Richard,

> Command line tools are ideal for use with scripts and with Source Code
> Control systems, especially with large multi-person multi-year projects.

Disagree. CrossWorks has the ability to seamlessly interface & integrate with various source
control systems. A lot of scripting is possible.
Hell, there's even Java script capability for various things like eg. kernel awareness for
debugging, transparent peripheral simulation et al.

> Command line systems are great for running test harnesses.

Agree, but I wonder how many non-IDE (or IDE for that matter) users here actually use test
harnesses... ?

> Windows based IDEs are ideal for debugging small chunks of code and/or
> developing one-man projects.

Urban legend, if you ask me.
I seem to hear these sorts of claims of people that don't use IDEs for all sorts of reasons,
except for the _actual_ (non-disclosed) reason they don't use them ....
I could effortlessly develop very large projects on the CW IDE. In fact I could do it much better
& faster than on a dumb command line....

> There is a place for both ways of working.

Probably true. But not for me and countless others I think.

Everyone's prerogative of course - but I've used command line crap in the '80s. Things have
changed a lot since then.
I presume you've used both (IDE & non-IDE) - benefit of the doubt. But have you actually tried a
powerful IDE such as CrossWorks ? If not, how could you possibly advocate the non-use of it ?? Or
realise what a massive amount of time it saves, especially for large projects ?

Besides, when you set up a new project, how long do you have to f*ck around with linker scripts
etc ? In CW IDE I can start a new project in about 3 secs, spanning an endless array of targets
and all my project information is visible in ONE glance, ALL of it.
I think of all the poor sods that still frequently ask how to generate map files, and Sherlock
Holmes around in their outputs. In the CW IDE the Project Explorer neatly displays total project
RAM & code usage, each individual module's usage (next to the project node/sub node/ module names
in the project hierachical tree), while I can concurrently see all my symbols and source
information, their address, size, place in memory, their type, what parameters functions use &
what types, where constants are defined and used. All these things can be re-sorted by various
parameters in an instant with mouse click. All source modules of my choice are neatly displayed
with a tabbed arrangement, I can instantly compare different versions of modules and have
highlighted where objects have been added or deleted, where the differences are, if any.
I have all the different targets commercially available concurrently displayed too. A double click
on a different target (with neat icons) and I can start debugging through different targets,
including simulator. 1 Second later I'm in the debugger in C, mixed or ASM mode. Have you tried
changing target on even a high end tool such as IAR ? It's a lot of navigating around in the
Project Options !!!
Now, while I can see this massive wealth of information all at once and in a glance I can also see
the properties of all objects I work with, automatically updated as I'm active on them.
There is sooo much more to cover, especially debugger wise.

I have tried to refrain from going on and on about how advanced CrossWorks is for a long time now,
but to be honest it's completely and utterly beyond me how anyone would WANT to work with anything
else.....

Someone brought up the "stopwatch" issue in MPLAB up recently & asked where it is in IAR.
The workspace taken to simply display CPU cycles takes ZERO workspace in CW (it's in the status
bar at bottom), in these other tools it steals about 10-15% of the workspace !
Resetting it is a song and dance on these other tools, on CW it's merely a double click with the
mouse.

I could go on & on (but I won't), but I just can't comprehend how a command line is supposed to be
"better". Again I've used both and it has me stumped....

I stress that my opinions above by no means are intended to make any reflection on you Richard,
but purely to support & substantiate my claims.

Why can't a project be developed much more timely on an IDE and - should it be necessary - then be
run on the command line version to run test harnesses ?
If anyone finds a command line superior, then I respect that, but it would have to be supported.
So far I haven't seen a single claim that does in the history of this group.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of Richard (UK).
Sent: Sunday, 12 August 2007 3:43 AM
To: m...
Subject: Re: [msp430] Re: Anyone did decimal arithmatic on MSP430 in runtime??

>> Anyone on this group that still re-asserts DOS-ish use of tools should
>> get real

Command line tools are ideal for use with scripts and with Source Code
Control systems, especially with large multi-person multi-year projects.

Command line systems are great for running test harnesses.

Windows based IDEs are ideal for debugging small chunks of code and/or
developing one-man projects.

There is a place for both ways of working.
Reply by "Richard (UK)." August 11, 20072007-08-11
>> Anyone on this group that still re-asserts DOS-ish use of tools should
>> get real

Command line tools are ideal for use with scripts and with Source Code
Control systems, especially with large multi-person multi-year projects.

Command line systems are great for running test harnesses.

Windows based IDEs are ideal for debugging small chunks of code and/or
developing one-man projects.

There is a place for both ways of working.
Reply by Microbit August 11, 20072007-08-11
Hi Lichen,

I hadn't followed the whole thread (I should have), but perhaps the OP did a "180" :-)
You're absolutely right - the subject after all is "decimal arithmetic", not "hexadecimal".
I think the OP's last post (that I replied to) threw me out. He said he wanted hex digits.
Of course I wasn't suggesting to first convert to Hex and then decimal, that would just
be dumb :-)

I don't understand though why you would prefer globals to make debugging easier ?

A decent debugger will display locals just as faithfully (when in scope of course).
I'm used to CrossWorks and surely that would be the Rolls Royce of debuggers when in debug mode.
Anyone on this group that still re-asserts DOS-ish use of tools should get real IMO...
(Have they even tried such a modern IDE, and how extremely powerful this debugger is ??
(or the whole IDE for that matter) ).

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of old_cow_yellow
Sent: Sunday, 12 August 2007 1:50 AM
To: m...
Subject: [msp430] Re: Anyone did decimal arithmatic on MSP430 in runtime??

Jugging from Kris' comment,it is obvious that I did not express myself
clearly.

The eventual goal is to display a 16-bit integer on a 5-digit
7-segment LCD in "decimal", not in "hexadecimal". Am I incorrect?

In order to convert a 16-bit integer into 5 decimal-digits, you do not
need to first convert into 4 hexadecimal-digits and then convert those
hexadecimal-digits into decimal-digits. You can do it directly.

In the short code example I posted previously, please note that:

(a) I declared value, dig1, etc. as global variables. This way, the
compiler probably will allocate SRAM at 0x0200, 0x202, etc. This makes
Debugging, Watch Windows, etc. easier. After you debugged it, you can
move the globals to locals to save SRAM usage.
(b) I declared value, digi1, etc. as int. You may want to change them
to unsigned int. Both way work (in their respective domain).
(c) What I called "value" is what you called "full_val" in your
earlier code.
(d) What I called "dig1" etc. are what you called "disp_dig1" etc. in
your earlier code.

Anyway, my code is getting the final decimal-digits directly without
going through the intermediate steps you have in mind. Try it, and
look at the Watch Window to see if dig1, etc. are what you want the
7-segment LCD to display.

--- In m..., "Microbit" wrote:
>
> Yes, but Europus is doing a modulo 16, not 10 :
>
> value = 0x4141; /*** or any other number ***/
> // NOT NEEDED dig1 = value/0x10000;
> dig2 = (value%0x10000)/0x1000;
> dig3 = (value%0x1000)/0x100;
> dig4 = (value%0x100)/0x10;
> dig5 = (value%0x10);
>
> Of course it's much easier to just shift right by the proper number
of nibbles...
> It depends, the modulo lib function might use shift arithmetic when
the modulo is a power of 2.
>
> Best Regards,
> Kris
>
>
> -----Original Message-----
> From: m... [mailto:m...] On
Behalf Of old_cow_yellow
> Sent: Saturday, 11 August 2007 2:31 PM
> To: m...
> Subject: [msp430] Re: Anyone did decimal arithmatic on MSP430 in
runtime??
>
> This will only take a few minuets.
> Try the following code:
>
> int value;
> int dig1, dig2, dig3, dig4, dig5;
> void main( void )
> {
> value = 0x4141; /*** or any other number ***/
> dig1 = value/10000;
> dig2 = (value%10000)/1000;
> dig3 = (value%1000)/100;
> dig4 = (value%100)/10;
> dig5 = (value%10);
> }
>
> Open a Watch Window to show dig1, dig2, dig3, dig4, dig5.
> What do you see? (I see 1, 6, 7, 0, 5 respectively.)
>
> --- In m..., alex ander wrote:
> >
> > No no....see , the idea was to separate the 1's ,10's ,100's and
> 1000's digits in hex first
> > and then multiply each one weighted....i.e suppose let;s take
> 0X4141 example so ....
> > dig1= 4 ,dig2=1 ,dig3 =4 and dig4=1 so now when you multiply
> dig1 by 4096 (decimal)....then it will be 16384..i.e decimal
> equivalent of 0X4000.....then similar for 0X100...
> > then 0X40 and then 0X01.....so the addition should look like
> > 16384 + 256 + 64 + 1 = 16705......
> > But while performing the above task, the compiler hold
> just some random values which do not change. i.e 0X0000030CD..like
> wise. ...
> > I guess what i was not able to get was the compiler is
> handling things differently
> > than a normal GCC C compiler or a calculator....
> > But i guess i will try code at the bottom and let you
> know.....It looks simple enough to
> > work....Thanks for your help old_cow....
> >
> > old_cow_yellow wrote:
> > Let us assume a "value" of 0x4141. The decimal
> representation of this
> > "value" is 16705. Thus the first decimal digit is 1 (not 4). The
> > second decimal digit is 6 (not 1). The third is 7 (not 4). The fourth
> > is 0 (not 1). And there is a fifth decimal digit, which equals 5.
> >
> > The following code will produce the correct decimal digits.
> >
> > dig1 = value / 10000;
> > dig2 = (value % 10000) / 1000;
> > dig3 = (value % 1000) / 100;
> > dig4 = (value % 100) / 10;
> > dig5 = value % 10;
> >
> > --- In m..., alex ander wrote:
> > >
> > > Thanks a lot Bill, Infact i am doing something similar but not
> > able to get further than there
> > > in converting to either BCD or decimal . Here is how i separated
> > digits. Value is raw ADC
> > > count in Hex.
> > >
> > >
> > > dig1= (value & 0XF000)/0X1000; //isolate dig 1//
> > > dig2= (value & 0X0F00)/0X100; //isolate dig 2//
> > > dig3= (value & 0X00F0)/0X10; //isolate dig 3//
> > > dig4= (value & 0X000F); //isolate dig 4//
> > >
> > > In the 1st line , i can clearly see 4 for input of 0X4141
> > in watch window
> > > But then stuck on how to obtain 20480 , equivalent decimal
> > for 0X5000 + 2560 for 0X0A00. ...and so on and then mutually add
> > them or OR them to obtain 23245 (decimal equivalent of 0X5ACD).
> > >
> > >
> > > Bill Knight wrote:
> > > If is BCD to binary, how about this? (I just hacked it
> > together and
> > > have not run it through a compiler or anything, but it will
hopefully
> > > give you the idea.)
> > >
> > > Regards
> > > -Bill Knight
> > > R O SoftWare
> > >
> > > unsigned bcd2bin(unsigned bcd)
> > > {
> > > unsigned resut = 0;
> > > unsigned multiplier = 1;
> > >
> > > while (bcd)
> > > {
> > > result += ((bcd & 0x0F) * multiplier);
> > > bcd >>= 4;
> > > multiplier *= 10;
> > > }
> > >
> > > return result;
> > > }
> > >
> > > Jose I Quinones wrote:
> > > > Do you mean BCD?
> > > >
> > > > Data is always stored in binary. Hexadecimal is just a notation of
> > four bits
> > > > to make it easier to write it down.
> > > >
> > > > In a way, it really does not matter how the data is stored as
> > while the
> > > > program is running, why would we care? Unless of course you have
> > to display
> > > > it!
> > > >
> > > > What I have done before (this applies to all sorts of programming)
> > is deduct
> > > > the digits from the number at hand. Have in mind that this
> depends on
> > > > whether your hex is 8 bit *max of 255) or 16 bits (max of 65535).
> > Then you
> > > > can see how many times you can subtract a thousand, a hundred, a
> > ten, etc.
> > > > from the original number and then the respective reminder as you
> > go on. Per
> > > > example, for the number 234, you can subtract a 100 2 times and
> > now you have
> > > > 34, from which you can subtract ten three times and now you have
> > four. These
> > > > would be your three BCD digits. This of course does not sound too
> > clean.
> > > >
> > > > I am thinking there are a bunch of BCD functions out there to
> > manipulate the
> > > > hex numbers. Also make sure the hex number is not already BCD
> > coded in which
> > > > case each nibble represents a decimal digit.
> > > >
> > > > Hope the info helps. Best regards,
> > > > JIQ
> > > > _____
> > > >
> > > > From: m... [mailto:m...] On
> > Behalf Of
> > > > europus
> > > > Sent: Monday, July 30, 2007 12:01 PM
> > > > To: m...
> > > > Subject: [msp430] Anyone did decimal arithmatic on MSP430 in
> runtime??
> > > >
> > > >
> > > >
> > > > Hi there,
> > > > I want to know if anyone converted hex data into decimal
> > > > in C compiler ...If yes..how did you manage ? Thanks in
> > > > advance..
> > >
> > >
> > >
> > >
> > >
> > >
> > > ---------------------------------
> > > Ready for the edge of your seat? Check out tonight's top picks on
> > Yahoo! TV.
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Looking for a deal? Find great prices on flights and hotels with
> Yahoo! FareChase.
> >
> >
> >
>
> Yahoo! Groups Links
>

Yahoo! Groups Links
Reply by old_cow_yellow August 11, 20072007-08-11
Jugging from Kris' comment,it is obvious that I did not express myself
clearly.

The eventual goal is to display a 16-bit integer on a 5-digit
7-segment LCD in "decimal", not in "hexadecimal". Am I incorrect?

In order to convert a 16-bit integer into 5 decimal-digits, you do not
need to first convert into 4 hexadecimal-digits and then convert those
hexadecimal-digits into decimal-digits. You can do it directly.

In the short code example I posted previously, please note that:

(a) I declared value, dig1, etc. as global variables. This way, the
compiler probably will allocate SRAM at 0x0200, 0x202, etc. This makes
Debugging, Watch Windows, etc. easier. After you debugged it, you can
move the globals to locals to save SRAM usage.
(b) I declared value, digi1, etc. as int. You may want to change them
to unsigned int. Both way work (in their respective domain).
(c) What I called "value" is what you called "full_val" in your
earlier code.
(d) What I called "dig1" etc. are what you called "disp_dig1" etc. in
your earlier code.

Anyway, my code is getting the final decimal-digits directly without
going through the intermediate steps you have in mind. Try it, and
look at the Watch Window to see if dig1, etc. are what you want the
7-segment LCD to display.

--- In m..., "Microbit" wrote:
>
> Yes, but Europus is doing a modulo 16, not 10 :
>
> value = 0x4141; /*** or any other number ***/
> // NOT NEEDED dig1 = value/0x10000;
> dig2 = (value%0x10000)/0x1000;
> dig3 = (value%0x1000)/0x100;
> dig4 = (value%0x100)/0x10;
> dig5 = (value%0x10);
>
> Of course it's much easier to just shift right by the proper number
of nibbles...
> It depends, the modulo lib function might use shift arithmetic when
the modulo is a power of 2.
>
> Best Regards,
> Kris
>
>
> -----Original Message-----
> From: m... [mailto:m...] On
Behalf Of old_cow_yellow
> Sent: Saturday, 11 August 2007 2:31 PM
> To: m...
> Subject: [msp430] Re: Anyone did decimal arithmatic on MSP430 in
runtime??
>
> This will only take a few minuets.
> Try the following code:
>
> int value;
> int dig1, dig2, dig3, dig4, dig5;
> void main( void )
> {
> value = 0x4141; /*** or any other number ***/
> dig1 = value/10000;
> dig2 = (value%10000)/1000;
> dig3 = (value%1000)/100;
> dig4 = (value%100)/10;
> dig5 = (value%10);
> }
>
> Open a Watch Window to show dig1, dig2, dig3, dig4, dig5.
> What do you see? (I see 1, 6, 7, 0, 5 respectively.)
>
> --- In m..., alex ander wrote:
> >
> > No no....see , the idea was to separate the 1's ,10's ,100's and
> 1000's digits in hex first
> > and then multiply each one weighted....i.e suppose let;s take
> 0X4141 example so ....
> > dig1= 4 ,dig2=1 ,dig3 =4 and dig4=1 so now when you multiply
> dig1 by 4096 (decimal)....then it will be 16384..i.e decimal
> equivalent of 0X4000.....then similar for 0X100...
> > then 0X40 and then 0X01.....so the addition should look like
> > 16384 + 256 + 64 + 1 = 16705......
> > But while performing the above task, the compiler hold
> just some random values which do not change. i.e 0X0000030CD..like
> wise. ...
> > I guess what i was not able to get was the compiler is
> handling things differently
> > than a normal GCC C compiler or a calculator....
> > But i guess i will try code at the bottom and let you
> know.....It looks simple enough to
> > work....Thanks for your help old_cow....
> >
> > old_cow_yellow wrote:
> > Let us assume a "value" of 0x4141. The decimal
> representation of this
> > "value" is 16705. Thus the first decimal digit is 1 (not 4). The
> > second decimal digit is 6 (not 1). The third is 7 (not 4). The fourth
> > is 0 (not 1). And there is a fifth decimal digit, which equals 5.
> >
> > The following code will produce the correct decimal digits.
> >
> > dig1 = value / 10000;
> > dig2 = (value % 10000) / 1000;
> > dig3 = (value % 1000) / 100;
> > dig4 = (value % 100) / 10;
> > dig5 = value % 10;
> >
> > --- In m..., alex ander wrote:
> > >
> > > Thanks a lot Bill, Infact i am doing something similar but not
> > able to get further than there
> > > in converting to either BCD or decimal . Here is how i separated
> > digits. Value is raw ADC
> > > count in Hex.
> > >
> > >
> > > dig1= (value & 0XF000)/0X1000; //isolate dig 1//
> > > dig2= (value & 0X0F00)/0X100; //isolate dig 2//
> > > dig3= (value & 0X00F0)/0X10; //isolate dig 3//
> > > dig4= (value & 0X000F); //isolate dig 4//
> > >
> > > In the 1st line , i can clearly see 4 for input of 0X4141
> > in watch window
> > > But then stuck on how to obtain 20480 , equivalent decimal
> > for 0X5000 + 2560 for 0X0A00. ...and so on and then mutually add
> > them or OR them to obtain 23245 (decimal equivalent of 0X5ACD).
> > >
> > >
> > > Bill Knight wrote:
> > > If is BCD to binary, how about this? (I just hacked it
> > together and
> > > have not run it through a compiler or anything, but it will
hopefully
> > > give you the idea.)
> > >
> > > Regards
> > > -Bill Knight
> > > R O SoftWare
> > >
> > > unsigned bcd2bin(unsigned bcd)
> > > {
> > > unsigned resut = 0;
> > > unsigned multiplier = 1;
> > >
> > > while (bcd)
> > > {
> > > result += ((bcd & 0x0F) * multiplier);
> > > bcd >>= 4;
> > > multiplier *= 10;
> > > }
> > >
> > > return result;
> > > }
> > >
> > > Jose I Quinones wrote:
> > > > Do you mean BCD?
> > > >
> > > > Data is always stored in binary. Hexadecimal is just a notation of
> > four bits
> > > > to make it easier to write it down.
> > > >
> > > > In a way, it really does not matter how the data is stored as
> > while the
> > > > program is running, why would we care? Unless of course you have
> > to display
> > > > it!
> > > >
> > > > What I have done before (this applies to all sorts of programming)
> > is deduct
> > > > the digits from the number at hand. Have in mind that this
> depends on
> > > > whether your hex is 8 bit *max of 255) or 16 bits (max of 65535).
> > Then you
> > > > can see how many times you can subtract a thousand, a hundred, a
> > ten, etc.
> > > > from the original number and then the respective reminder as you
> > go on. Per
> > > > example, for the number 234, you can subtract a 100 2 times and
> > now you have
> > > > 34, from which you can subtract ten three times and now you have
> > four. These
> > > > would be your three BCD digits. This of course does not sound too
> > clean.
> > > >
> > > > I am thinking there are a bunch of BCD functions out there to
> > manipulate the
> > > > hex numbers. Also make sure the hex number is not already BCD
> > coded in which
> > > > case each nibble represents a decimal digit.
> > > >
> > > > Hope the info helps. Best regards,
> > > > JIQ
> > > > _____
> > > >
> > > > From: m... [mailto:m...] On
> > Behalf Of
> > > > europus
> > > > Sent: Monday, July 30, 2007 12:01 PM
> > > > To: m...
> > > > Subject: [msp430] Anyone did decimal arithmatic on MSP430 in
> runtime??
> > > >
> > > >
> > > >
> > > > Hi there,
> > > > I want to know if anyone converted hex data into decimal
> > > > in C compiler ...If yes..how did you manage ? Thanks in
> > > > advance..
> > >
> > >
> > >
> > >
> > >
> > >
> > > ---------------------------------
> > > Ready for the edge of your seat? Check out tonight's top picks on
> > Yahoo! TV.
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Looking for a deal? Find great prices on flights and hotels with
> Yahoo! FareChase.
> >
> >
> >
>
> Yahoo! Groups Links
>
Reply by Microbit August 11, 20072007-08-11
Yes, but Europus is doing a modulo 16, not 10 :

value = 0x4141; /*** or any other number ***/
// NOT NEEDED dig1 = value/0x10000;
dig2 = (value%0x10000)/0x1000;
dig3 = (value%0x1000)/0x100;
dig4 = (value%0x100)/0x10;
dig5 = (value%0x10);

Of course it's much easier to just shift right by the proper number of nibbles...
It depends, the modulo lib function might use shift arithmetic when the modulo is a power of 2.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of old_cow_yellow
Sent: Saturday, 11 August 2007 2:31 PM
To: m...
Subject: [msp430] Re: Anyone did decimal arithmatic on MSP430 in runtime??

This will only take a few minuets.
Try the following code:

int value;
int dig1, dig2, dig3, dig4, dig5;
void main( void )
{
value = 0x4141; /*** or any other number ***/
dig1 = value/10000;
dig2 = (value%10000)/1000;
dig3 = (value%1000)/100;
dig4 = (value%100)/10;
dig5 = (value%10);
}

Open a Watch Window to show dig1, dig2, dig3, dig4, dig5.
What do you see? (I see 1, 6, 7, 0, 5 respectively.)

--- In m..., alex ander wrote:
>
> No no....see , the idea was to separate the 1's ,10's ,100's and
1000's digits in hex first
> and then multiply each one weighted....i.e suppose let;s take
0X4141 example so ....
> dig1= 4 ,dig2=1 ,dig3 =4 and dig4=1 so now when you multiply
dig1 by 4096 (decimal)....then it will be 16384..i.e decimal
equivalent of 0X4000.....then similar for 0X100...
> then 0X40 and then 0X01.....so the addition should look like
> 16384 + 256 + 64 + 1 = 16705......
> But while performing the above task, the compiler hold
just some random values which do not change. i.e 0X0000030CD..like
wise. ...
> I guess what i was not able to get was the compiler is
handling things differently
> than a normal GCC C compiler or a calculator....
> But i guess i will try code at the bottom and let you
know.....It looks simple enough to
> work....Thanks for your help old_cow....
>
> old_cow_yellow wrote:
> Let us assume a "value" of 0x4141. The decimal
representation of this
> "value" is 16705. Thus the first decimal digit is 1 (not 4). The
> second decimal digit is 6 (not 1). The third is 7 (not 4). The fourth
> is 0 (not 1). And there is a fifth decimal digit, which equals 5.
>
> The following code will produce the correct decimal digits.
>
> dig1 = value / 10000;
> dig2 = (value % 10000) / 1000;
> dig3 = (value % 1000) / 100;
> dig4 = (value % 100) / 10;
> dig5 = value % 10;
>
> --- In m..., alex ander wrote:
> >
> > Thanks a lot Bill, Infact i am doing something similar but not
> able to get further than there
> > in converting to either BCD or decimal . Here is how i separated
> digits. Value is raw ADC
> > count in Hex.
> >
> >
> > dig1= (value & 0XF000)/0X1000; //isolate dig 1//
> > dig2= (value & 0X0F00)/0X100; //isolate dig 2//
> > dig3= (value & 0X00F0)/0X10; //isolate dig 3//
> > dig4= (value & 0X000F); //isolate dig 4//
> >
> > In the 1st line , i can clearly see 4 for input of 0X4141
> in watch window
> > But then stuck on how to obtain 20480 , equivalent decimal
> for 0X5000 + 2560 for 0X0A00. ...and so on and then mutually add
> them or OR them to obtain 23245 (decimal equivalent of 0X5ACD).
> >
> >
> > Bill Knight wrote:
> > If is BCD to binary, how about this? (I just hacked it
> together and
> > have not run it through a compiler or anything, but it will hopefully
> > give you the idea.)
> >
> > Regards
> > -Bill Knight
> > R O SoftWare
> >
> > unsigned bcd2bin(unsigned bcd)
> > {
> > unsigned resut = 0;
> > unsigned multiplier = 1;
> >
> > while (bcd)
> > {
> > result += ((bcd & 0x0F) * multiplier);
> > bcd >>= 4;
> > multiplier *= 10;
> > }
> >
> > return result;
> > }
> >
> > Jose I Quinones wrote:
> > > Do you mean BCD?
> > >
> > > Data is always stored in binary. Hexadecimal is just a notation of
> four bits
> > > to make it easier to write it down.
> > >
> > > In a way, it really does not matter how the data is stored as
> while the
> > > program is running, why would we care? Unless of course you have
> to display
> > > it!
> > >
> > > What I have done before (this applies to all sorts of programming)
> is deduct
> > > the digits from the number at hand. Have in mind that this
depends on
> > > whether your hex is 8 bit *max of 255) or 16 bits (max of 65535).
> Then you
> > > can see how many times you can subtract a thousand, a hundred, a
> ten, etc.
> > > from the original number and then the respective reminder as you
> go on. Per
> > > example, for the number 234, you can subtract a 100 2 times and
> now you have
> > > 34, from which you can subtract ten three times and now you have
> four. These
> > > would be your three BCD digits. This of course does not sound too
> clean.
> > >
> > > I am thinking there are a bunch of BCD functions out there to
> manipulate the
> > > hex numbers. Also make sure the hex number is not already BCD
> coded in which
> > > case each nibble represents a decimal digit.
> > >
> > > Hope the info helps. Best regards,
> > > JIQ
> > > _____
> > >
> > > From: m... [mailto:m...] On
> Behalf Of
> > > europus
> > > Sent: Monday, July 30, 2007 12:01 PM
> > > To: m...
> > > Subject: [msp430] Anyone did decimal arithmatic on MSP430 in
runtime??
> > >
> > >
> > >
> > > Hi there,
> > > I want to know if anyone converted hex data into decimal
> > > in C compiler ...If yes..how did you manage ? Thanks in
> > > advance..
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Ready for the edge of your seat? Check out tonight's top picks on
> Yahoo! TV.
> >
> >
> >
>
>
> ---------------------------------
> Looking for a deal? Find great prices on flights and hotels with
Yahoo! FareChase.
>
>
>

Yahoo! Groups Links
Reply by old_cow_yellow August 11, 20072007-08-11
This will only take a few minuets.
Try the following code:

int value;
int dig1, dig2, dig3, dig4, dig5;
void main( void )
{
value = 0x4141; /*** or any other number ***/
dig1 = value/10000;
dig2 = (value%10000)/1000;
dig3 = (value%1000)/100;
dig4 = (value%100)/10;
dig5 = (value%10);
}

Open a Watch Window to show dig1, dig2, dig3, dig4, dig5.
What do you see? (I see 1, 6, 7, 0, 5 respectively.)

--- In m..., alex ander wrote:
>
> No no....see , the idea was to separate the 1's ,10's ,100's and
1000's digits in hex first
> and then multiply each one weighted....i.e suppose let;s take
0X4141 example so ....
> dig1= 4 ,dig2=1 ,dig3 =4 and dig4=1 so now when you multiply
dig1 by 4096 (decimal)....then it will be 16384..i.e decimal
equivalent of 0X4000.....then similar for 0X100...
> then 0X40 and then 0X01.....so the addition should look like
> 16384 + 256 + 64 + 1 = 16705......
> But while performing the above task, the compiler hold
just some random values which do not change. i.e 0X0000030CD..like
wise. ...
> I guess what i was not able to get was the compiler is
handling things differently
> than a normal GCC C compiler or a calculator....
> But i guess i will try code at the bottom and let you
know.....It looks simple enough to
> work....Thanks for your help old_cow....
>
> old_cow_yellow wrote:
> Let us assume a "value" of 0x4141. The decimal
representation of this
> "value" is 16705. Thus the first decimal digit is 1 (not 4). The
> second decimal digit is 6 (not 1). The third is 7 (not 4). The fourth
> is 0 (not 1). And there is a fifth decimal digit, which equals 5.
>
> The following code will produce the correct decimal digits.
>
> dig1 = value / 10000;
> dig2 = (value % 10000) / 1000;
> dig3 = (value % 1000) / 100;
> dig4 = (value % 100) / 10;
> dig5 = value % 10;
>
> --- In m..., alex ander wrote:
> >
> > Thanks a lot Bill, Infact i am doing something similar but not
> able to get further than there
> > in converting to either BCD or decimal . Here is how i separated
> digits. Value is raw ADC
> > count in Hex.
> >
> >
> > dig1= (value & 0XF000)/0X1000; //isolate dig 1//
> > dig2= (value & 0X0F00)/0X100; //isolate dig 2//
> > dig3= (value & 0X00F0)/0X10; //isolate dig 3//
> > dig4= (value & 0X000F); //isolate dig 4//
> >
> > In the 1st line , i can clearly see 4 for input of 0X4141
> in watch window
> > But then stuck on how to obtain 20480 , equivalent decimal
> for 0X5000 + 2560 for 0X0A00. ...and so on and then mutually add
> them or OR them to obtain 23245 (decimal equivalent of 0X5ACD).
> >
> >
> > Bill Knight wrote:
> > If is BCD to binary, how about this? (I just hacked it
> together and
> > have not run it through a compiler or anything, but it will hopefully
> > give you the idea.)
> >
> > Regards
> > -Bill Knight
> > R O SoftWare
> >
> > unsigned bcd2bin(unsigned bcd)
> > {
> > unsigned resut = 0;
> > unsigned multiplier = 1;
> >
> > while (bcd)
> > {
> > result += ((bcd & 0x0F) * multiplier);
> > bcd >>= 4;
> > multiplier *= 10;
> > }
> >
> > return result;
> > }
> >
> > Jose I Quinones wrote:
> > > Do you mean BCD?
> > >
> > > Data is always stored in binary. Hexadecimal is just a notation of
> four bits
> > > to make it easier to write it down.
> > >
> > > In a way, it really does not matter how the data is stored as
> while the
> > > program is running, why would we care? Unless of course you have
> to display
> > > it!
> > >
> > > What I have done before (this applies to all sorts of programming)
> is deduct
> > > the digits from the number at hand. Have in mind that this
depends on
> > > whether your hex is 8 bit *max of 255) or 16 bits (max of 65535).
> Then you
> > > can see how many times you can subtract a thousand, a hundred, a
> ten, etc.
> > > from the original number and then the respective reminder as you
> go on. Per
> > > example, for the number 234, you can subtract a 100 2 times and
> now you have
> > > 34, from which you can subtract ten three times and now you have
> four. These
> > > would be your three BCD digits. This of course does not sound too
> clean.
> > >
> > > I am thinking there are a bunch of BCD functions out there to
> manipulate the
> > > hex numbers. Also make sure the hex number is not already BCD
> coded in which
> > > case each nibble represents a decimal digit.
> > >
> > > Hope the info helps. Best regards,
> > > JIQ
> > > _____
> > >
> > > From: m... [mailto:m...] On
> Behalf Of
> > > europus
> > > Sent: Monday, July 30, 2007 12:01 PM
> > > To: m...
> > > Subject: [msp430] Anyone did decimal arithmatic on MSP430 in
runtime??
> > >
> > >
> > >
> > > Hi there,
> > > I want to know if anyone converted hex data into decimal
> > > in C compiler ...If yes..how did you manage ? Thanks in
> > > advance..
> >
> >
> >
> >
> >
> >
> > ---------------------------------
> > Ready for the edge of your seat? Check out tonight's top picks on
> Yahoo! TV.
> >
> >
> >
>
>
> ---------------------------------
> Looking for a deal? Find great prices on flights and hotels with
Yahoo! FareChase.
>
>
>
Reply by alex ander August 10, 20072007-08-10
No no....see , the idea was to separate the 1's ,10's ,100's and 1000's digits in hex first
and then multiply each one weighted....i.e suppose let;s take 0X4141 example so ....
dig1= 4 ,dig2=1 ,dig3 =4 and dig4=1 so now when you multiply dig1 by 4096 (decimal)....then it will be 16384..i.e decimal equivalent of 0X4000.....then similar for 0X100...
then 0X40 and then 0X01.....so the addition should look like
16384 + 256 + 64 + 1 = 16705......
But while performing the above task, the compiler hold just some random values which do not change. i.e 0X0000030CD..like wise. ...
I guess what i was not able to get was the compiler is handling things differently
than a normal GCC C compiler or a calculator....
But i guess i will try code at the bottom and let you know.....It looks simple enough to
work....Thanks for your help old_cow....

old_cow_yellow wrote:
Let us assume a "value" of 0x4141. The decimal representation of this
"value" is 16705. Thus the first decimal digit is 1 (not 4). The
second decimal digit is 6 (not 1). The third is 7 (not 4). The fourth
is 0 (not 1). And there is a fifth decimal digit, which equals 5.

The following code will produce the correct decimal digits.

dig1 = value / 10000;
dig2 = (value % 10000) / 1000;
dig3 = (value % 1000) / 100;
dig4 = (value % 100) / 10;
dig5 = value % 10;

--- In m..., alex ander wrote:
>
> Thanks a lot Bill, Infact i am doing something similar but not
able to get further than there
> in converting to either BCD or decimal . Here is how i separated
digits. Value is raw ADC
> count in Hex.
> dig1= (value & 0XF000)/0X1000; //isolate dig 1//
> dig2= (value & 0X0F00)/0X100; //isolate dig 2//
> dig3= (value & 0X00F0)/0X10; //isolate dig 3//
> dig4= (value & 0X000F); //isolate dig 4//
>
> In the 1st line , i can clearly see 4 for input of 0X4141
in watch window
> But then stuck on how to obtain 20480 , equivalent decimal
for 0X5000 + 2560 for 0X0A00. ...and so on and then mutually add
them or OR them to obtain 23245 (decimal equivalent of 0X5ACD).
> Bill Knight wrote:
> If is BCD to binary, how about this? (I just hacked it
together and
> have not run it through a compiler or anything, but it will hopefully
> give you the idea.)
>
> Regards
> -Bill Knight
> R O SoftWare
>
> unsigned bcd2bin(unsigned bcd)
> {
> unsigned resut = 0;
> unsigned multiplier = 1;
>
> while (bcd)
> {
> result += ((bcd & 0x0F) * multiplier);
> bcd >>= 4;
> multiplier *= 10;
> }
>
> return result;
> }
>
> Jose I Quinones wrote:
> > Do you mean BCD?
> >
> > Data is always stored in binary. Hexadecimal is just a notation of
four bits
> > to make it easier to write it down.
> >
> > In a way, it really does not matter how the data is stored as
while the
> > program is running, why would we care? Unless of course you have
to display
> > it!
> >
> > What I have done before (this applies to all sorts of programming)
is deduct
> > the digits from the number at hand. Have in mind that this depends on
> > whether your hex is 8 bit *max of 255) or 16 bits (max of 65535).
Then you
> > can see how many times you can subtract a thousand, a hundred, a
ten, etc.
> > from the original number and then the respective reminder as you
go on. Per
> > example, for the number 234, you can subtract a 100 2 times and
now you have
> > 34, from which you can subtract ten three times and now you have
four. These
> > would be your three BCD digits. This of course does not sound too
clean.
> >
> > I am thinking there are a bunch of BCD functions out there to
manipulate the
> > hex numbers. Also make sure the hex number is not already BCD
coded in which
> > case each nibble represents a decimal digit.
> >
> > Hope the info helps. Best regards,
> > JIQ
> > _____
> >
> > From: m... [mailto:m...] On
Behalf Of
> > europus
> > Sent: Monday, July 30, 2007 12:01 PM
> > To: m...
> > Subject: [msp430] Anyone did decimal arithmatic on MSP430 in runtime??
> >
> >
> >
> > Hi there,
> > I want to know if anyone converted hex data into decimal
> > in C compiler ...If yes..how did you manage ? Thanks in
> > advance..
> ---------------------------------
> Ready for the edge of your seat? Check out tonight's top picks on
Yahoo! TV.
>
>
>

---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.