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
int
Signed 32-bit
long
Signed 64-bit
Unsigned 8-bit
n/a
ushort
Unsigned 16-bit
uint
Unsigned 32-bit
ulong
Unsigned 64-bit
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
{
public class UnsignedArithematic
void Method(long l, uint u)
l = MethodReturnsUInt();
l = u + MethodReturnsUInt();
u = MethodReturnsUInt();
l = MethodReturnsUIntArray()[0];
}
uint MethodReturnsUInt()
return 42;
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 *********
private void method(long l, /*uint*/long u)
l = (methodReturnsUInt() & 0xFFFFFFFFL);
l = (u & 0xFFFFFFFFL) + (methodReturnsUInt() & 0xFFFFFFFFL);
u = methodReturnsUInt();
l = (methodReturnsUIntArray()[0] & 0xFFFFFFFFL);
private /*uint*/long methodReturnsUInt()
private /*uint*/long[] methodReturnsUIntArray()
/*uint*/long[] uints = { 42, 127, 155 };
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