Velocity Reviews > C++ > converting LARGE decimal number to binary stream

# converting LARGE decimal number to binary stream

Mariusz Sakowski
Guest
Posts: n/a

 03-19-2005
I'm writing class which will be able to store large numbers (my
ambition is to make it able to operand on thousands of bits) and
perform various operations on it (similiar to those available with int
type). I want to store the number as binary stream, and I don't know
how to convert large decimal string (char*) to binary stream.
Converting using MOD would last for hours with really big numbers, and
in fact I don't know any other ways to convert decimal to binary.

Maybe someone could advice me how to do it? (i thought of converting
digit by digit and adding it to final stream using fast operator+
function, already implemented to work on binary streams, but again how
could I convert number like k*(10^n), where n could be thousands, to
binary?)

I'll appreciate any help, and am sorry for my poor english.

osmium
Guest
Posts: n/a

 03-19-2005
"Mariusz Sakowski" writes:

> I'm writing class which will be able to store large numbers (my
> ambition is to make it able to operand on thousands of bits) and
> perform various operations on it (similiar to those available with int
> type). I want to store the number as binary stream, and I don't know
> how to convert large decimal string (char*) to binary stream.
> Converting using MOD would last for hours with really big numbers, and
> in fact I don't know any other ways to convert decimal to binary.
>
> Maybe someone could advice me how to do it? (i thought of converting
> digit by digit and adding it to final stream using fast operator+
> function, already implemented to work on binary streams, but again how
> could I convert number like k*(10^n), where n could be thousands, to
> binary?)

How about using BCD arithmetic? In a four-bit nibble store values 0-9.
Handle the sign as a separate issue. This will be slower and use more RAM,
but the simplicity gained makes it seem a reasonable tradeoff to me.

Edernity
Guest
Posts: n/a

 03-19-2005
cze,
how will you justify using such number without float?
Isn't that what float is for, very huge number with lots of zero.
Unless you need a super precision which still useable by bigger float.
If binary manipulation you are looking for u do need a converter of
number to bit representation straight into memory/reserve data
structure. BCD is ok but rather slow for this.
Edernity
-----------
THESE ARE FROM MY PREVIOUS POST. I just wanna say this last time.
Mercy, Mercy for one without one will be condemn and damn ...ops darn
by God

ALRIGHT I'M GIVING ALL THAT ALREADY READ THIS A CHANCE (THIS NG),
pls help. If my posting is useless I'll go. Remeber that God hate
miser.
if it help (IT DON'T CAUSE YOU A CENT. JUST 1 EMAIL THEN FILLING FORMS)
please do help me provide better school supplies for childrenof
indonesia.
IN FACT, for those other who already read this plea and maybe finding
my post helpful, what is I give you one dollars for it. I don't believe
this, I'm paying to get people to donate to kids?!!!???that really
ugly!
it may be a donation but I merely ask you to letme send email to you
from one of the product of I'm affiliated and please register there on
mechant account free. If you even want you refund back on your dollar
of i-kard, its ok, I'll send you just use regular delivery on shipping
please. Please note this is very safe since this is a bonafid company.
u can add or remove more credit cards into your account. you can/should
also ask for always confirmation on send out to you. That will get
those savage cracker bloke out. even u can use some more free teen
refillable visa/mastercard from your bank cc account (can be obtaion
free).
It is just unnerving seeing how can people do not do anything as so
they need so little. \$10 could support {{{{{the child 1 month.}}}}
Still have doubts, sign on a personal account and let me contact you
again on it. just one mail pls
also
I'm also affiliated to this site:
www.getaportal.com/portals/edd y_ruslim
Unless u wanto e-gold it at 1369872
New to egold:www.e-gold.com/e-gold.asp?cid= 1369872
NAH, previous way cost u zilch
God bless