Eyegor <> writes:
> I am working on a project, just for fun of it, so there is no 3rd
> party restictions.
> What I am trying to do is to write a simple bignum library, simmilar
> to GMP. I know GMP exists and it works and I am not going to write
> anything better than what it is, this is just for learning purposes.
> Anyhow, I creaed several basic functions to add and subtract large
> numbers which are basically Array Encoded Integers. I use 16-bit
> signed integers as elements in the array, and the whole array
> represents a very large integer, say 16000 bits or so.
Why are you using *signed* integers? I'd think that unsigned
integers would be more convenient. If you have a bignum represented
as an array of 1000 16-bit integers, you only need 1 sign bit,
not a thousand of them.
> The problem I ran into is writing a replica of scanf function.
> Basically I want to comvert a decimal input like
> 67627457272523772428537372395768 into the binary array. Any suggestion
> on how to do this would be greatly appreciated. I dont actually need
> the code, just an algorithm suggestion. I wrote a printf function like
> this about 5 years ago, but I dont have that code anymore and want to
> replicate it.
Presumably you've already got functions that implement the arithmetic
operators (+, -, *, /, %) for your Array Encoded Integers. Just use
them to implement the string-to-bignum conversion in the same way
you'd implement a string-to-integer conversion. It's the same
algorithm (which I presume you already know or can find or invent),
just using different operations.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"