Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31234
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-02-27 03:04 -0800 |
| References | <fbfdf843-2a45-4e59-a0c4-70020b6982cf@googlegroups.com> <slrnmf0jej.uoi.avl@login.logic.tuwien.ac.at> |
| Message-ID | <deeace69-ed4b-4411-9b27-9bc0207c474d@googlegroups.com> (permalink) |
| Subject | Re: string comparison of big integers |
| From | burian.vlastimil2@gmail.com |
On Friday, February 27, 2015 at 11:58:38 AM UTC+1, Andreas Leitgeb wrote:
> Vlastimil Burian <burian.vlastimil2@gmail.com> wrote:
> > The code is in C#, but it should be understandable to you all.
>
> > } while ((I < Number1.Length) && (GetDigitValue(Number1[I]) >= GetDigitValue(Number2[I])));
>
> I think the mistake is here.
Yes. It was there.
Working code:
private int CompareNumbers(string Number1, string Number2, Int16 NumSystem)
{
if ((NumSystem < 2) || (NumSystem > 36))
throw new InvalidNumberSystem();
if (!NumberValid(Number1, NumSystem))
throw new InvalidNumberSystem();
if (!NumberValid(Number2, NumSystem))
throw new InvalidNumberSystem();
int I = -1;
Number1 = Number1.TrimStart('0');
Number2 = Number2.TrimStart('0');
if (Number1 == Number2) return 0; else
if (Number1.Length < Number2.Length) return -1; else
if (Number1.Length > Number2.Length) return 1; else
{
do {
I++;
} while ((I < Number1.Length) && (GetDigitValue(Number1[I]) == GetDigitValue(Number2[I])));
}
if ((I < Number1.Length) && (GetDigitValue(Number1[I]) <= GetDigitValue(Number2[I])))
return -1;
else
return 1;
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
string comparison of big integers Vlastimil Burian <burian.vlastimil2@gmail.com> - 2015-02-26 21:43 -0800
Re: string comparison of big integers Joerg Meier <joergmmeier@arcor.de> - 2015-02-27 08:21 +0100
Re: string comparison of big integers Vlastimil Burian <burian.vlastimil2@gmail.com> - 2015-02-26 23:28 -0800
Re: string comparison of big integers Vlastimil Burian <burian.vlastimil2@gmail.com> - 2015-02-26 23:53 -0800
Re: string comparison of big integers Joerg Meier <joergmmeier@arcor.de> - 2015-02-27 09:12 +0100
Re: string comparison of big integers Arne Vajhøj <arne@vajhoej.dk> - 2015-02-27 07:04 -0500
Re: string comparison of big integers Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-02-27 10:57 +0000
Re: string comparison of big integers burian.vlastimil2@gmail.com - 2015-02-27 03:04 -0800
Re: string comparison of big integers Arne Vajhøj <arne@vajhoej.dk> - 2015-02-27 11:23 -0500
Re: string comparison of big integers Martin Gregorie <martin@address-in-sig.invalid> - 2015-02-27 11:08 +0000
csiph-web