How to convert binary to BCD ?

C, C++, Visual C++, C++.Net Topics
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

Re: How to convert binary to BCD ?

Post by Saman » Sat Jan 26, 2013 3:19 am

Why 26 bit ? Cant represent more than 26 bit numbers ?
Is Reason for limit ,for 32 bit output? :idea:
The maximum number which can show in 26-bits is (226 - 1) = 67108863
There are 8 digits which needs 8 nibbles of 4 bytes.

Now consider (227 - 1)... it is 134217728 and it has 9 digits.
It needs 9 nibbles. That is 4-bytes and another nibble which can't be accommodated in a 32-bit integer type.

So for your question, answer is yes.

If you select the return type to be a 64-bit type such as long long or __int64, then you can represent 16-digits with those.
User avatar
Nandika
Captain
Captain
Posts: 247
Joined: Sat Oct 15, 2011 11:40 am
Location: Galle-Sri Lanka

Re: How to convert binary to BCD ?

Post by Nandika » Sat Jan 26, 2013 8:51 am

Thank Saman

Completely clear all.. :)

Thank All friends...
:yahoo:
User avatar
penlock
Posts: 1
Joined: Fri Sep 27, 2013 3:04 pm

Re: How to convert binary to BCD ?

Post by penlock » Fri Sep 27, 2013 3:07 pm

Hi everyone.. kak kak :clap: :clap:
User avatar
Drew2
Posts: 1
Joined: Wed Mar 12, 2014 3:30 pm

Re: How to convert binary to BCD ?

Post by Drew2 » Wed Mar 12, 2014 3:35 pm

Thanks for the post!
Post Reply

Return to “C/C++ Programming”