SPL Array - Convert byte[] to ushort, int or vice versa
1. Convert value(ushort) to byte[]
- You can convert value into byte[] array by using below methods.
|
|
|
- Add script as follows.
| |
clear
val = 0x01FF
buff = Util.UShortToBytes(val)
print "buff -> " + Util.BytesToHex(buff)
| |
|
- Executed result is as follows.
2. Convert value of uint type into byte[] array
- You can convert value of uint type into array by using below method.
Util.UIntToBytes(uint val)
- Add script as follows.
| |
clear
val = 0x01A0B0C0
buff = Util.UIntToBytes(val)
print "buff -> " + Util.BytesToHex(buff)
| |
|
- Executed result is as follows.
3. Convert byte[] to value(ushort)
- You can convert byte[] into value by using below methods.
- Add script as follows.
| |
clear
buff = Util.CreateArrayByte(2)
buff[0] = 0x10
buff[1] = 0x11
val = Util.BytesToUShort(buff)
print "val -> " + val
| |
|
- Executed result is as follows.
4. Convert byte[] into value of uint type
- You can convert byte[] into uint typed variable by using below method.
Util.BytesToUInt(byte[] buff)
- Add script as follows.
| |
clear
buff = Util.CreateArrayByte(4)
buff[0] = 0x10
buff[1] = 0x11
buff[2] = 0x01
buff[3] = 0x01
val = Util.BytesToUInt(buff)
print "val -> " + val
| |
|
- Executed result is as follows.
|