Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,158,780 members, 7,837,837 topics. Date: Thursday, 23 May 2024 at 11:26 AM

How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# (4410 Views)

Problem Using A Numeric Key From Keyboard To Trigger An Event In Vb.net / How To Convert A Python File (.py) To Exe (.exe) / [problem] Write A Program In C++ That Finds The Hcf Of 2 Numbers Without Using A Recursive Function (2) (3) (4)

(1) (Reply) (Go Down)

How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by samyu1: 3:46pm On Jun 23, 2009
I used the following code but this has stack overflow since Int64 accepts only 18-digits and I had 20-digit lenght value which need to be converted from base10 to base36

public static string Base36Encode(long value)
{
char[] base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
string returnValue = "";
while (value != 0)
{
returnValue = base36Chars[value % base36Chars.Length] + returnValue;
value /= 36;
}
return returnValue;
}

Any help is appreciated

Thank you in advance
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Seun(m): 10:29pm On Jun 24, 2009
Use the decimal data type instead long Long Int.
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by samyu1: 3:10pm On Jun 25, 2009
Thank you seun. But that doesn't work I am getting Integral constant is too large . Actually I am trying to convert this number 20090521003032796356 and expecting output as like this 00048MZBBINX8FD0.

Thank you
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Kobojunkie: 2:23am On Jun 26, 2009
in C#, you can use ulong. The type allows up to 20 digits.
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Akpangbon: 12:55pm On Jun 26, 2009
Kobojunkie:

in C#, you can use ulong. The type allows up to 20 digits.

Who teach this one programming?
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by samyu1: 2:29pm On Jun 26, 2009
I tried ulong double and decimal everything that's not working I am getting the same problem Integral constant is too large
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Kobojunkie: 3:12pm On Jun 26, 2009
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by samyu1: 3:58pm On Jun 26, 2009
Both seperately i.e I tried ulong seperately and double seperately when I am using double I am not getting the same value as I expected the last 2-digits differ ex: 20090521003032797856 expected 00048MZBBINX8GIO
getting
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000048MZBBINX8G00

any way leading zeros need to be tide up

When I am using ulong I am getting integral constant is too large

Thank you
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Kobojunkie: 4:01pm On Jun 26, 2009
Try the plugin I sent you. It comes highly recommended. Yes, Ulong only works with 20 digits up to a certain range. I just figured that out now.
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Seun(m): 10:35am On Jun 27, 2009
the number he's trying to convert is only 20 digits long.
Re: How To Convert A 20-digit Numeric Value From Base10 To Base36 In C# by Kobojunkie: 1:24pm On Jun 27, 2009
integral types have ranges. The range he is working with is beyond that of uint, ulong etc.

(1) (Reply)

Oracle 10g On Solaris Os / I Will Officially Quit Visiting This Section / Is Nairaland A Threat To Nairaland?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.