Click here to Skip to main content
16,022,798 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
i need to create a class that deals with multiple precision numbers
and i need to represent this new type as char ,
for example '214587954'
i would need to convert each number into binary take of the added ASCII 4 bits
which means that i need to represent each number in 4 bits
and after define all the available operators
help please i don't even know where to start
thank you
Posted
Comments
Sergey Alexandrovich Kryukov 22-Dec-15 16:48pm    
"Convert each number into binary" is absurd. Everything is binary, only character '2' can be understood are representation of integer value 2, or as ASCII with the value 50. With both, you can perform arithmetic operation, as well as with 214587954 interpreted as number.

You never mentioned what you want to achieve and what's the problem.

—SA
Member 12223678 22-Dec-15 16:57pm    
i need to create a class that deals with big numbers of 50 digits and more
that is what i want to achieve
Sergey Alexandrovich Kryukov 22-Dec-15 16:58pm    
This is not achieved this way. You should have started with your goal.
—SA
Member 12223678 22-Dec-15 17:03pm    
sorry i didn't know a better way to describe the problem
but i still need to declare the numbers as i would a char here is an example
Mint x,y,z="1245698763214689799842321"
mint is the name of the class
Sergey Alexandrovich Kryukov 22-Dec-15 17:11pm    
Look, I did not want to write about it in my answer, but I feel you are trying to think in a wrong way: using strings representing data instead of data itself.
And the idea to "perform arithmetic operation on char" it especially wrong.

I would understand if you asked about "arithmetic operation" on string, such as
BitInt b("123");
b += 11;
b *= "321";
...

But it would be different thing; and "arithmetic operations on char" would still not be useful. Calculations on strings are quite possible, but this is not how bigInt is usually implemented. The data behind such type is usually binary, say, array of bytes...

But of course, any decent BigInt library should include initialization from string. If such constructor is missing, it's way too easy to add. The library should have such operations as power and multiplication, with operator overloading for bitInt operands and combinations with all CPU integer types. Apparently, the number represented by each decimal character in the string is value * power(10, N), where N is the position of the digit (from right, of course), and value is the numeric value corresponding to the digit (for '2', it's 2, not 50 :-).

—SA

1 solution

Please see my comments to the question. This is not how such thing should be implemented. Traditionally, this is called "Bit integer" or "bitInt". You can easily find appropriate implementation: http://bfy.tw/3PSZ[^].

In particular, you can find one implementation here: https://gmplib.org[^].

Another one is here: http://sourceforge.net/projects/ttmath[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900