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
Phone: +61 2 8901 3609
Email: support [@] codeporting [dot] com
Â