Answer the question
In order to leave comments, you need to log in
How to implement long arithmetic?
Good afternoon.
I set out to implement long arithmetic. There are a lot of articles on the Internet about how to implement this using an array of numbers with a base that is a multiple of 10. There are no questions here, we break the number into blocks that are multiples of the selected base, and when outputting, we take into account cases when additional zeros need to be inserted.
But what if the power of two is chosen as the base? For example 2^8 .
The input is a number, for example 123456789 . There are no problems with splitting the array into cells (the low index corresponds to the low order):
12345678 =
--------------------------------
2^0 2^8 2^16 2^24
[21] [205] [91] [7]
A_0 * 2^0 + A_1 * 2^8 + A_2 * 2^16 + ... + A_n * 2 ^ (n * 8)
Answer the question
In order to leave comments, you need to log in
When outputting, you can first convert from a long number in base 2 to a long number in base 10
Look at OpenSSL and how it's all implemented there. At the same time, you may not have to reinvent the wheel unnecessarily.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question