Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Transform Array<UShort> to Array <UByte>
- * Antonio Villanueva Segura
- */
- fun main() {
- var ushortArray = arrayOf<UShort> ( 0x1234U , 0x5678U , 0x9ABCU , 0xDEF0U )
- println ( printUByteArray (toArrayUByte(ushortArray)) )
- }
- //Transform Array<UShort> TO Array<UByte>
- fun toArrayUByte(a:Array<UShort>):Array<UByte>{
- var b=Array<UByte> (a.size *2){0U} //The UByte array is twice the UShort array
- for (i in a.indices ){
- b[i*2]=a[i].toInt().shr(8).toUByte() //H Byte
- b[i*2 + 1]=a[i].toUByte() //L Byte
- }
- return b //Returns Array<UByte>
- }
- //Print function to watch UByte Array
- fun printUByteArray(a:Array<UByte>){
- for (elem in a ){
- println (elem.toString(16)) //Conversion HEX 0x
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement