Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Convert::NativeToInt64 for multiple base conversions #855

Merged
merged 2 commits into from
Sep 15, 2018
Merged

Fix Convert::NativeToInt64 for multiple base conversions #855

merged 2 commits into from
Sep 15, 2018

Conversation

MatthiasJentsch
Copy link
Contributor

@MatthiasJentsch MatthiasJentsch commented Sep 14, 2018

Description

A few tweaks for fixing issue #412: Convert::NativeToInt64 with SUPPORT_ANY_BASE_CONVERSION delivers incorrect results

Motivation and Context

How Has This Been Tested?

Tested with various Convert.Toxxx calls. All deliver the correct results. Here is the test code:

using System;

namespace NFApp2
{
	public class Program
	{
		public static void Main()
		{
			// -42
			// binary
			sbyte b1 = Convert.ToSByte("11010110", 2);
			// octal
			sbyte b2 = Convert.ToSByte("326", 8);
			// decimal
			sbyte b3 = Convert.ToSByte("-42");
			// hexadecimal
			sbyte b4 = Convert.ToSByte("D6", 16);

			// -17078
			// binary
			short x1 = Convert.ToInt16("1011110101001010", 2);
			// octal
			short x2 = Convert.ToInt16("136512", 8);
			// decimal
			short x3 = Convert.ToInt16("-17078");
			// hexadecimal
			short x4 = Convert.ToInt16("BD4A", 16);

			// -1234567890
			// binary
			int i1 = Convert.ToInt32("10110110011010011111110100101110", 2);
			// octal
			int i2 = Convert.ToInt32("26632376456", 8);
			// decimal
			int i3 = Convert.ToInt32("-1234567890");
			// hexadecimal
			int i4 = Convert.ToInt32("B669FD2E", 16);

			// -4446419168141639693
			// binary
			long l1 = Convert.ToInt64("1100001001001011001001010101001100100000011011011111111111110011", 2);
			// octal
			long l2 = Convert.ToInt64("1411131125144033377763", 8);
			// decimal
			long l3 = Convert.ToInt64("-4446419168141639693");
			// hexadecimal
			long l4 = Convert.ToInt64("C24B2553206DFFF3", 16);

			// 14000324905567911923
			// binary
			ulong u1 = Convert.ToUInt64("1100001001001011001001010101001100100000011011011111111111110011", 2);
			// octal
			ulong u2 = Convert.ToUInt64("1411131125144033377763", 8);
			// decimal
			ulong u3 = Convert.ToUInt64("14000324905567911923");
			// hexadecimal
			ulong u4 = Convert.ToUInt64("C24B2553206DFFF3", 16);
		}
	}
}

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: Matthias Jentsch info@matthias-jentsch.de

…RT_ANY_BASE_CONVERSION delivers incorrect results

Signed-off-by: Matthias Jentsch <info@matthias-jentsch.de>
@nfbot
Copy link
Member

nfbot commented Sep 14, 2018

Hi @MatthiasJentsch,

I'm nanoFramework bot.
Thank you for your contribution!

A human will be reviewing it shortly. 😉

@josesimoes josesimoes added Type: bug Area: Common libs Everything related with common libraries labels Sep 14, 2018
@josesimoes josesimoes changed the title A few tweaks for fixing issue #412: Convert::NativeToInt64 with SUPPO… Fix Convert::NativeToInt64 for multiple base conversions Sep 14, 2018
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MatthiasJentsch MatthiasJentsch merged commit 92f8b1b into nanoframework:develop Sep 15, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Common libs Everything related with common libraries Type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert::NativeToInt64 with SUPPORT_ANY_BASE_CONVERSION delivers incorrect results
3 participants