Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *swap function with generic parameters for Int KOTLIN
- * Antonio Villanueva Segura
- */
- fun main() {
- var ushort:UShort=0xABCDU //UShort kotlin.Unit
- var uint:UInt=0x1234U //UInt kotlin.Unit
- var int:Int=0x5678 //UInt kotlin.Unit
- var short:Int=0x9ABC //UInt kotlin.Unit
- println ( "%04x".format (swap (ushort.toInt())))
- println ( "%04x".format (swap (uint.toInt())))
- println ( "%04x".format (swap (int.toInt())))
- println ( "%04x".format (swap (short.toInt())))
- }
- //Swap Fun
- fun <T>swap(w:T) :T{
- var H:UShort=0x00U
- var L:UShort=0x00U
- if ( (w is Int) ){ //Test Only Int
- H=( w.toInt().shr(8) ).toUShort()
- L=( w.toInt().shl(8) ).toUShort()
- return ((H or L).toInt() ) as T
- }
- return w //No changed error
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement