String to uint in MS4

Jan 14, 2012 at 8:45 AM
Edited Jan 14, 2012 at 9:02 AM

I want to convert a string to uint is it possible? Im using MS4, Is there a plug or something?

Jan 14, 2012 at 3:35 PM
Edited Jan 14, 2012 at 4:16 PM
gamesman123 wrote:

I want to convert a string to uint is it possible? Im using MS4, Is there a plug or something?

Actually we used to do it like this:

 

public static uint ToUint(string str) {
for (uint i  = 0; i < 999999;i++) {
     if (i.ToString() == str) {
      return i;
     }
  }
}

That code should work fine, If not let me know and ill go fish it out of my source and find the exact code. Thanks - Matt

edit the code should now work.

Jan 14, 2012 at 3:37 PM

That code is unacceptable

On Jan 14, 2012 10:35 AM, "civilwarrock" <notifications@codeplex.com> wrote:

From: civilwarrock

gamesman123 wrote:

I want to convert a string to uint is it possible? Im using MS4, Is there a plug or something?

Actually we used to do it like this:

public static uint ToUint(string str) {
for (uint i  = 0; i < 999999;i++) {
     if (i == str) {
      return i;
     }
  }
}

That code should work fine, If not let me know and ill go fish it out of my source and find the exact code. Thanks - Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jan 14, 2012 at 4:19 PM
d1ag0n wrote:

That code is unacceptable

On Jan 14, 2012 10:35 AM, "civilwarrock" <notifications@codeplex.com> wrote:

From: civilwarrock

gamesman123 wrote:

I want to convert a string to uint is it possible? Im using MS4, Is there a plug or something?

Actually we used to do it like this:

 

public static uint ToUint(string str) {
for (uint i  = 0; i < 999999;i++) {
     if (i == str) {
      return i;
     }
  }
}

That code should work fine, If not let me know and ill go fish it out of my source and find the exact code. Thanks - Matt

 

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

why is it unacceptable? Why because it didnt work? It does now. Thanks - Matt

Developer
Jan 14, 2012 at 4:30 PM

Civil is correct, that is how we originally did string->uint conversion :P The current method is a lot faster :P

Jan 14, 2012 at 4:35 PM
No because you're using brute force.
I have an implementation that uses mathematics to come to the result.
I'm testing it now. Only 4294400000 tests to go :)

but here's the code.

The math class(hehe) may or may not need to contain what it does. This is only tested in .net not for cosmos but it may work. I'll test it when I have a chance there.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
class Program
{
static void Main(string[] args)
{

string s;

for (uint i = 0; i < uint.MaxValue; i++)
{
string inpt = i.ToString();
uint result = Math.atoi(inpt);
if (result != i)
{
throw new Exception();
}
Console.WriteLine(uint.MaxValue - i);
}

}
}

public static class Math
{
private static uint PowHlpr(uint o, uint x, uint y)
{
uint result = o * x;
y--;
if (y > 0)
{
result = PowHlpr(result, x, y);
}
return result;
}

public static uint Pow(uint x, uint y)
{
if (y < 2)
{
return x;
}
uint result = x * x;
y -= 2;
if (y > 0)
{
result = PowHlpr(result, x, y);
}
return result;
}

public static uint atoi(string s)
{
uint len = (uint)s.Length;
uint factor = Pow(10, len);
uint result = 0;
for (int j = 0; j < len; j++)
{
switch (s[j])
{
case '0':
break;
case '1':
result += 1 * factor;
break;
case '2':
result += 2 * factor;
break;
case '3':
result += 3 * factor;
break;
case '4':
result += 4 * factor;
break;
case '5':
result += 5 * factor;
break;
case '6':
result += 6 * factor;
break;
case '7':
result += 7 * factor;
break;
case '8':
result += 8 * factor;
break;
case '9':
result += 9 * factor;
break;
default :
throw new Exception("Input string was not in a correct format.");
}
factor /= 10;
}
return result / 10;
}
}
}





On Sat, Jan 14, 2012 at 11:19 AM, civilwarrock <notifications@codeplex.com> wrote:

From: civilwarrock

d1ag0n wrote:

That code is unacceptable

On Jan 14, 2012 10:35 AM, "civilwarrock" <notifications@codeplex.com> wrote:

From: civilwarrock

gamesman123 wrote:

I want to convert a string to uint is it possible? Im using MS4, Is there a plug or something?

Actually we used to do it like this:

public static uint ToUint(string str) {
for (uint i  = 0; i < 999999;i++) {
     if (i == str) {
      return i;
     }
  }
}

That code should work fine, If not let me know and ill go fish it out of my source and find the exact code. Thanks - Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

why is it unacceptable? Why because it didnt work? It does now. Thanks - Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Jan 14, 2012 at 4:36 PM

:P we do use math to come to the answer in the current version :P Also, you'll find that the entire System.Math class has already been plugged by me in the devkit :P

Jan 14, 2012 at 4:39 PM
Oh ok. Well is my code total crap or is it somewhat decent?

On Sat, Jan 14, 2012 at 11:36 AM, blah38621 <notifications@codeplex.com> wrote:

From: blah38621

:P we do use math to come to the answer in the current version :P Also, you'll find that the entire System.Math class has already been plugged by me in the devkit :P

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jan 14, 2012 at 4:48 PM
Ok it's crap, just looking at it I think it will fail on larger neumbers :D

On Sat, Jan 14, 2012 at 11:38 AM, Nathan Stiles <stiles.nathan@gmail.com> wrote:
Oh ok. Well is my code total crap or is it somewhat decent?


On Sat, Jan 14, 2012 at 11:36 AM, blah38621 <notifications@codeplex.com> wrote:

From: blah38621

:P we do use math to come to the answer in the current version :P Also, you'll find that the entire System.Math class has already been plugged by me in the devkit :P

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com



Jan 14, 2012 at 5:12 PM

Hey Blah38612 how/where is this actually done?  The string to uint part I mean.

Jan 15, 2012 at 9:16 AM

Thanks Guys :)



Coordinator
Jan 16, 2012 at 8:12 AM
d1ag0n: your best bet is to just move to the devkit (if possible). be sure to convert your kernel then...
What VS version and edition do you use?

On Sun, Jan 15, 2012 at 10:16 AM, Gamesman123 <notifications@codeplex.com> wrote:

From: Gamesman123

Thanks Guys :)



Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com