[NXC][API][SE] Use of bcd2dec
[NXC][API][SE] Use of bcd2dec
Please answer this question on the Electronics SE website.
Last edited by muntoo on 05 Mar 2011, 06:18, edited 1 time in total.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Use of NXC function bcd2dec
According to the help files, it looks like it would return the number 5 if you were to pass the number 101 into it. Or return 42 52 (thanks Andy) if you pass 101010 into it. It looks like it converts a binary appearing number into the decimal equivalent to it. I'll test to confirm what the help file appears to say.
Last edited by mattallen37 on 26 Feb 2011, 08:54, edited 1 time in total.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Use of NXC function bcd2dec
Ok, I did some tests, and it always returns 0. I don't know if it doesn't work, or if I am doing something wrong (not likely with only one line of relevant code).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 323
- Joined: 29 Sep 2010, 05:03
Re: Use of NXC function bcd2dec
Well I've no idea what the bcd2dec NXC function actually does but the decimal equiv of bcd 101010 is 52 (or possibly 25 depending on your nibble order!) not 42... You treat the two nibbles as a binary codec decimal digit so 010 is 2 and 101 is 5.... as to 0x3a well 0xa is not a valid bcd value...
Andy (who is old enough to remember when microprocessors had instructions to manipulate bcd *and* programmers actually used them!)
Andy (who is old enough to remember when microprocessors had instructions to manipulate bcd *and* programmers actually used them!)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Use of NXC function bcd2dec
Yes, you are right. Duh me, I don't know what I was thinking. Sorry.gloomyandy wrote:...the decimal equiv of bcd 101010 is 52 (or possibly 25 depending on your nibble order!) not 42...
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Use of NXC function bcd2dec
I remember using CMOS BCD converter chips for controlling 7 segment displays Oh, that's a long time ago.
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Use of NXC function bcd2dec
I remember that as well, but it wasn't all that long ago for me (maybe 4-6 years). Actually, a project I did not too long ago (maybe a year ago) for the NXT used some of them. It was a 4 x 7-segment display for the NXT.mightor wrote:I remember using CMOS BCD converter chips for controlling 7 segment displays Oh, that's a long time ago.
- Xander
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Use of NXC function bcd2dec
So is the API function in NXC working or not? It is used by the Mindsensors RTClock API function so it was working once upon a time when I tested that API function. Here's the code that is generated when you use bcd2dec:
I guess this would return "invalid" decimal values if you input invalid bcd values. I don't think I will bother adding a check that the result of the mod operation is less than 10. I will update the docs with a proper example, though.
John Hansen
Code: Select all
acquire __bcd2DecMutex
div __bcd2DecTens, _bcd, 16
mod __bcd2DecOnes, _bcd, 16
mul _result, __bcd2DecTens, 10
add _result, _result, __bcd2DecOnes
release __bcd2DecMutex
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Use of NXC function bcd2dec
Well, it seems like "not" to me.afanofosc wrote:So is the API function in NXC working or not?...
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Use of NXC function bcd2dec
Could you post the NXC and NBC code for a simple program that always produces 0 when you call bcd2dec?
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Who is online
Users browsing this forum: Semrush [Bot] and 1 guest