## [NXC][API][SE] Use of bcd2dec

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.

### [NXC][API][SE] Use of bcd2dec

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

muntoo

Posts: 834
Joined: 01 Oct 2010, 02:54

### 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

mattallen37

Posts: 1816
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

### 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

mattallen37

Posts: 1816
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

### 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!)

gloomyandy

Posts: 320
Joined: 29 Sep 2010, 05:03

### Re: Use of NXC function bcd2dec

gloomyandy wrote:...the decimal equiv of bcd 101010 is 52 (or possibly 25 depending on your nibble order!) not 42...
Yes, you are right. Duh me, I don't know what I was thinking. Sorry.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting

mattallen37

Posts: 1816
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

### 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
| 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)

mightor

Posts: 1060
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands

### Re: Use of NXC function bcd2dec

mightor wrote:I remember using CMOS BCD converter chips for controlling 7 segment displays Oh, that's a long time ago.

- Xander

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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting

mattallen37

Posts: 1816
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

### 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:

Code: Select all
acquire __bcd2DecMutex
div __bcd2DecTens, _bcd, 16
mod __bcd2DecOnes, _bcd, 16
mul _result, __bcd2DecTens, 10
release __bcd2DecMutex

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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/

afanofosc

Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

### Re: Use of NXC function bcd2dec

afanofosc wrote:So is the API function in NXC working or not?...

Well, it seems like "not" to me.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting

mattallen37

Posts: 1816
Joined: 02 Oct 2010, 02:19
Location: Michigan USA

### 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/

afanofosc