troubleshooting Question

Transcribe Java Code to C# please help?

Avatar of Dynotoe
Dynotoe asked on
Java
2 Comments1 Solution489 ViewsLast Modified:
Hi Ladoes and Gents,

I am very new to Java and had a little code I would love some help with.  I basically need to get the associative C# version of this Java code.  Please if you could comment the heck out of the code to describe what it does on the c# versioni as well it would be greatly appreciated.

FYI I have tried to install the java to C# conversion assistant on a few different machines with different versions of visual studio with no luck.  I get an error message so a automated conversion is out.

Let me please relay my gracious thank you in advance.  I hope everyone is well.

Best - Dynotoe
public abstract class Data { 
    public long time; 
     
    public Data() { 
    } 
 
    public Data(long time) { 
        this.time = time; 
    } 
 
    public abstract void toBytes(byte[] buff, int off); 
     
    public abstract int getBytesCount(); 
 
    protected static final int putLong(final byte[] b, final int off, final long val) { 
        b[off + 7] = (byte) (val >>> 0); 
        b[off + 6] = (byte) (val >>> 8); 
        b[off + 5] = (byte) (val >>> 16); 
        b[off + 4] = (byte) (val >>> 24); 
        b[off + 3] = (byte) (val >>> 32); 
        b[off + 2] = (byte) (val >>> 40); 
        b[off + 1] = (byte) (val >>> 48); 
        b[off + 0] = (byte) (val >>> 56); 
        return off + 8; 
    } 
 
    protected static final int putDouble(final byte[] b, final int off, final double val) { 
        final long j = Double.doubleToLongBits(val); 
        b[off + 7] = (byte) (j >>> 0); 
        b[off + 6] = (byte) (j >>> 8); 
        b[off + 5] = (byte) (j >>> 16); 
        b[off + 4] = (byte) (j >>> 24); 
        b[off + 3] = (byte) (j >>> 32); 
        b[off + 2] = (byte) (j >>> 40); 
        b[off + 1] = (byte) (j >>> 48); 
        b[off + 0] = (byte) (j >>> 56); 
        return off + 8; 
    } 
 
    protected static final long getLong(final byte[] b, final int off) { 
        return ((b[off + 7] & 0xFFL) << 0) + 
                ((b[off + 6] & 0xFFL) << 8) + 
                ((b[off + 5] & 0xFFL) << 16) + 
                ((b[off + 4] & 0xFFL) << 24) + 
                ((b[off + 3] & 0xFFL) << 32) + 
                ((b[off + 2] & 0xFFL) << 40) + 
                ((b[off + 1] & 0xFFL) << 48) + 
                (((long) b[off + 0]) << 56); 
    } 
 
    protected static final double getDouble(final byte[] b, final int off) { 
        final long j = ((b[off + 7] & 0xFFL) << 0) + 
                ((b[off + 6] & 0xFFL) << 8) + 
                ((b[off + 5] & 0xFFL) << 16) + 
                ((b[off + 4] & 0xFFL) << 24) + 
                ((b[off + 3] & 0xFFL) << 32) + 
                ((b[off + 2] & 0xFFL) << 40) + 
                ((b[off + 1] & 0xFFL) << 48) + 
                (((long) b[off + 0]) << 56); 
        return Double.longBitsToDouble(j); 
    } 
 
    @Override 
    public int hashCode() { 
        final int prime = 31; 
        int result = 1; 
        result = prime * result + (int) (time ^ (time >>> 32)); 
        return result; 
    } 
 
    @Override 
    public boolean equals(Object obj) { 
        if (this == obj) 
            return true; 
        if (obj == null) 
            return false; 
        if (getClass() != obj.getClass()) 
            return false; 
        final Data other = (Data) obj; 
        if (time != other.time) 
            return false; 
        return true; 
    } 
}

Open in new window

ASKER CERTIFIED SOLUTION
spule

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros