September 1st, 2011, 5:32 pm
Is this right to extract a signed short in a byte array as an unsigned int? And then insert it back in signed? public static int ByteArrayExtractSignedShortUnsigned(byte[] b, int offset) { int value = 0; value = value + b[offset+1]; value = value ^ 128; value = value * 256; value = value + b[offset]; return value; } public static void UnsignedShortEmbedSignedToByteArray(byte[] b, int offset, int theshort) { int remain = theshort % 256; b[offset] = (byte) remain; theshort = theshort - remain; theshort = theshort / 256; theshort = theshort ^ 128; b[offset+1] = (byte) theshort; }