# Converting to BCD

3 replies to this topic

### #1 kdgarrisONLINE

kdgarris

Moonsweeper

• 267 posts

Posted Mon Jun 26, 2017 9:13 AM

I'm trying to convert a two-digit number in a variable to BCD to assign to a score variable, but it's not working as expected. I'm using the // operator to divide by 10, and multiply the result of that by 16, then add the contents of temp1, which should contain the remainder of the division operation. I've put this in a simple "hello world" skeleton where the fire button increments the variable, and tries to convert it and put it on one of the score variables. Does anyone know why this isn't working as I'm expecting it to? Thanks in advance for any advice.

helloworld.bas   1.03KB   28 downloads

### #2 Random TerrainONLINE

Random Terrain

Visual batari Basic User

• 28,608 posts
• Controlled Randomness
Replay Value
Nonlinear
• Location:North Carolina (USA)

Posted Mon Jun 26, 2017 1:27 PM

It looks like the bB page says that you need to use BCD compliant numbers.

http://www.randomter...tml#check_score

http://www.randomter...mmands.html#bcd

### #3 RevEngOFFLINE

RevEng

River Patroller

• 4,756 posts
• Bitnik
• Location:Canada

Posted Mon Jun 26, 2017 9:06 PM

The easiest way to deal with conversion to BCD is to keep the number in BCD format from the start. i.e., when you add and subtract, use the "dec" keyword in front of the assignment. (Just keep in mind that the 6502/7 doesn't handle BCD division or multiplication)

```   MyScore=\$10 ; BCD version of "10"
[...]
dec MyScore=Myscore+1
```

If really need to convert to BCD, Omegamatrix has a cool routine in assembly.

### #4 kdgarrisONLINE

kdgarris

Moonsweeper

• Topic Starter
• 267 posts

Posted Tue Jun 27, 2017 5:56 AM

Thanks!  I'm using my variable as a wave counter in a space game, and using the score to display the wave number at the beginning of the wave (blanking out the unneeded digits).  The question as to whether I should keep it in BCD format from the start or not depends on whether or not I want more than 100 waves then, I suppose.  That routine will be quite handy if I choose to allow for more than 100 waves, then.  Much appreciated.

#### 0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users