Mega Code Archive

 
Categories / C# / Data Types
 

Convert Byte to Short

using System;     public class Utility {                  public static short bytesToShort(byte highByte, byte lowByte, bool swapBytes) {             if (swapBytes) {                 return (short)((highByte & 0xff) + (lowByte & 0xff) << 8);             }             else {                 return (short)(((lowByte & 0xff) << 8) + (lowByte & 0xff));             }         }     }