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:

 

Code
namespace C#2Java.Samples.Convert.UnsignedArithmetic.UInt
Code
{
Code
    public class UnsignedArithematic
Code
    {
Code
        void Method(long l, uint u)
Code
        {
Code
            l = MethodReturnsUInt();
Code
            l = u + MethodReturnsUInt();
Code
            u = MethodReturnsUInt();
Code
Code
            l = MethodReturnsUIntArray()[0];
Code
        }
Code
Code
        uint MethodReturnsUInt()
Code
        {
Code
            return 42;
Code
        }
Code
Code
        uint[] MethodReturnsUIntArray()
Code
        {
Code
            uint[] uints = { 42, 127, 155 };
Code
            return uints;
Code
        }
Code
    }
Code
}

 

Java Code Generated by CodePorting:

 

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

 

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