 }
 
 func int16BigToHost(value:Int16) -> Int16 {
-    return (value << 8) | (value >> 8);
+    var hostVal : Int16 = value
+    return reverseBytes(&hostVal);
 }
 
 func int16HostToBig(value:Int16) -> Int16 {
     return (value << 8) | (value >> 8);
+}
+
+func byteArrayValue<T>(value:T) -> Byte[] {
+    let data = NSData(bytes:[value], length:sizeof(T))
+    var byteArray = Byte[](count:sizeof(T), repeatedValue:0)
+    data.getBytes(&byteArray, length:sizeof(T))
+    return byteArray
+}
+
+func reverseBytes<T>(inout value:T) {
+    var swappedBytes = NSData(bytes:byteArrayValue(value).reverse(), length:sizeof(T))
+    swappedBytes.getBytes(&value, length:sizeof(Int16))
 }
 
 extension NSData {


    // UInt16
    convenience init(uint16ToLittle value:UInt16) {
        self.init(bytes:[uint16HostToLittle(value)], length:1)
    }
    
    convenience init(uint16ArrayToLittle values:UInt16[]) {

    }
}

var test = NSData(int16ToBig:1000)
test.hexStringValue()
println(test.int16FromLittleValue())
