Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

N! up to 71 digits

Status
Not open for further replies.

sdTech

Programmer
Oct 29, 2002
10
0
0
US
Hi

I need to to N! and display to the screen up to 71 digits...I dont know how to do that...Would appreciate if anyone can help me with that..


Thanks

sd
 
You have two alternatives:
1) Use BCD. The Intel 80x86 series can work with BCD.
2) Use multi-word math. The Intel 80x86 series can also work with multiple words.

Personally I recommend the multi-word solution.

You can find some multi-word maths stuff on this forum in threads dukely started, asking about 64-bit maths. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
I tried to search it but didnt find anything...
 
Come now. N! is a LARGE number. So how do you handle large numbers which would overflow your processor's normal word, which is 32-bit? You use BCD or multi-word maths. Multi-word maths is prolly your best bet. It's up to YOU to wonder how your going to implement N!: N! is simply:
product X=2 to N of X
which you can implement in a loop. Doing the multiplication, however, requires knowledge of how to implement multiplication using several words.

The relevant threads are:
thread272-396253 threads discuss some stuff about multiplication.

Also, choose: multi-word maths or BCD?

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Thanks AmkG

Now the requirement changes to displaying up to 500 digits...the multi-word maths would not work. Someone told me using array to store single digit in each element..but i am not sure how to do it

Thanks
 
No, multi-word maths will still work. The only problem is that you have a LOT of work to do to implement it. In fact, using unpacked BCD (which is what you suggested, storing a single digit in one byte is unpacked BCD...) may be more difficult than using multi-word maths. The problem you have is writing a routine to convert a multi-word binary to a displayable decimal number, which is why you may want to use unpacked BCD. However once you've got the conversion routine licked, I suggest you use multi-word binary representation, especially since unpacked BCD can be s--- slow. "Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Thanks AmKG!!

I solved the problem. I used 2 array of 10000 elements each and just multiply digit by digit...i dont know the other ways...

Wishing you a happy holiday AmKG

sd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top