We have shown you in previous blog posts that how developers can translate C# properties to java using CodePorting C#2Java App.  CodePorting is determined to translate those C# language constructs to java code which are not available in java and this will be achieved by CodePorting C#2Java intelligent engine. Unsigned and signed data types contains same amount of memory in C#.  C# provides eight predefined signed and unsigned integer types whereas Java has four signed integer types and no unsigned ones.

See following table:

 

C# Type

Description

Java Equivalent

sbyte

Signed 8-bit

byte

short

Signed 16-bit

short

int

Signed 32-bit

int

long

Signed 64-bit

long

byte

Unsigned 8-bit

n/a

ushort

Unsigned 16-bit

n/a

uint

Unsigned 32-bit

n/a

ulong

Unsigned 64-bit

n/a

 

CodePorting C#2Java automatically converts C#’s unsigned integer types to higher signed types.  This eliminates the chances of data loss in arithmetic operations.

Following example converts C# unsigned integer type to java:

 

C# Code:

namespace C#2Java.Samples.Convert.UnsignedArithmetic.UInt
{
 Â Ã‚  publicclass UnsignedArithematic
 Â Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  voidMethod(long l, uint u)
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l = MethodReturnsUInt();
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l = u + MethodReturnsUInt();
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  u = MethodReturnsUInt();
 
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l = MethodReturnsUIntArray()[0];
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  }
 
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  uint MethodReturnsUInt()
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  return42;
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  }
 
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  uint[] MethodReturnsUIntArray()
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  uint[] uints ={42, 127, 155};
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  return uints;
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  }
 Â Ã‚  }
}

 

Java Code Generated by CodePorting:


package C#2Java.Samples.Convert.UnsignedArithmetic.UInt;
 
// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********
 
publicclass UnsignedArithematic
{
 Â Ã‚  privatevoid method(long l, /*uint*/long u)
 Â Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l =(methodReturnsUInt()& 0xFFFFFFFFL);
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l =(u & 0xFFFFFFFFL)+(methodReturnsUInt()& 0xFFFFFFFFL);
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  u = methodReturnsUInt();
 
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  l =(methodReturnsUIntArray()[0]& 0xFFFFFFFFL);
 Â Ã‚  }
 
 Â Ã‚  private/*uint*/long methodReturnsUInt()
 Â Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  return42;
 Â Ã‚  }
 
 Â Ã‚  private/*uint*/long[] methodReturnsUIntArray()
 Â Ã‚  {
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  /*uint*/long[] uints ={42, 127, 155};
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  return uints;
 Â Ã‚  }
}

 

It is clear for the above example that CodePorting C#2Java engine intelligently converts the C# unsigned data types to higher signs in java codes to avoid any data loss accuracy.

Newly added articles and documentation pages

- Automatically convert C# using statement to java using CodePorting Engine

- How to: Work with C# to Java Snippet Porting

- How to: Work with CodePorting Project Manager

- How to: Work with CodePorting Library Manager

 

Overview: Â  CodePorting C#2Java App

CodePorting helps you make your .NET applications cross platform compatible and allows migrating your .NET solutions, projects and files into Java in the cloud. Other than speed and accuracy of conversion; port your C# code directly either by uploading .cs files contained in a .zip file or import directly from popular version control repositories like GIT, Mercurial HG and SubVersion. You can also download a Microsoft Visual Studio plugin and convert C# code in the real time without leaving the development environment. You may also build your own customized code conversion applications using CodePorting APIs.

Read more about CodePorting

- Start converting C# Apps and source code to Java

- CodePorting Homepage

- CodePorting C#2Java Homepage

- CodePorting Documentation

- Watch out CodePorting introductory video

 

Contact Us

Suite 163, 79 Longueville Road

Lane Cove, NSW 2066, Australia

Web: http://codeporting.com/

Phone: +61 2 8901 3609

Email: support [@] codeporting [dot] com

Â