Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

large(ish) BCD to binary

Status
Not open for further replies.

kripacharya

Banned
Advanced Member level 4
Joined
Dec 28, 2012
Messages
1,204
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Visit site
Activity points
0
This is the opposite prob from what most folks want.

I need to convert a BCD number -- 6 digit -- into its binary/ hex equivalent. The BCD can be packed/ not packed. I prefer not-packed for now.

Can someone provide pointers to an 8-bit assembly implementation for an efficient algorithm ? Its for an AVR project, using Atmega48 as of now. Fair amount of RAM is available if required.

Once again -- this is BCD to Binary.
 

Essentially multiply digits by ten and add next digit. Repeat from left to right. Don't need other RAM than 16-Bit result variable.
 

Essentially multiply digits by ten and add next digit. Repeat from left to right. Don't need other RAM than 16-Bit result variable.

yes of course !! i was clearly too sleepy to see the obvious.
But i will need at least 20-bits for the result.

thanks & cheers!
 

But i will need at least 20-bits for the result.
Yes, of course. Unfortunately the least significant digit can overflow to any result bit, so you have to implement a full 24 Bit (or 32, when using standard number formats) adder.

Any reasons against utilizing a standard C compiler to implement the calculations?
 

Oh ? How would it overflow ? Max for 6-digit is 999,999 which fits in 20 bits. Anyhow I have to use 3x 8-bit regs so no troubles there.
This project is very tight on time/ real-time, and its somehow just easier to use assembly, where i can SEE everything. But other than that just force of habit.
Though i admit I sometimes copy bits of code output by gcc with optimisation set ;-)
 

Sorry for misunderstanding, I didn't mean overflow, just regular carry. In any case, it's normal integer math, nothing special.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top