>>22
バイトオーダー変換

func bth<T:UnsignedInteger>(_ v:T)->T{
switch v {
case let u as UInt16: return type(of:u).init(bigEndian:u) as! T
case let u as UInt32: return type(of:u).init(bigEndian:u) as! T
case let u as UInt64: return type(of:u).init(bigEndian:u) as! T
case let u as UInt : return type(of:u).init(bigEndian:u) as! T
default: return v
}
}
func lth<T:UnsignedInteger>(_ v:T)->T{
switch v {
case let u as UInt16: return type(of:u).init(littleEndian:u) as! T
case let u as UInt32: return type(of:u).init(littleEndian:u) as! T
case let u as UInt64: return type(of:u).init(littleEndian:u) as! T
case let u as UInt : return type(of:u).init(littleEndian:u) as! T
default: return v
}
}

ジェネリクスのめんどくさいところと、関数オーバーロードのメンテ性の悪さ
両方を兼ね備えてみました
無駄なプロトコル定義しなくて済むけどイマイチかっこいくないな