Playing with bytes...need to convert from java to C# -


i not used manipulate bytes in code , have piece of code written in java , need convert c# equivalent :

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; } 

thanks in advance help, looking forward learn this.

i appreciate know if there c# equivalent java function :

double.doubletolongbits(val); 

edit : found answer second question : bitconverter.doubletoint64bits

  1. you can't have final parameters in c#
  2. methods "final" default.
  3. there no unsigned shift right in c#

so get:

protected static int putlong(byte [] b, int off, 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; } 

for more information on c# bitwise shift operators: http://www.blackwasp.co.uk/csharpshiftoperators.aspx


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -