SPL Array - Convert byte[] to ushort, int or vice versa


1. Convert value(ushort) to byte[]
  1. You can convert value into byte[] array by using below methods.

 

  1. Add script as follows.

      
    clear
    
    val = 0x01FF
    
    buff = Util.UShortToBytes(val)
    
    print "buff -> " + Util.BytesToHex(buff)
    
      


  2. Executed result is as follows.




2. Convert value of uint type into byte[] array
  1. You can convert value of uint type into array by using below method.

       Util.UIntToBytes(uint val)

  2. Add script as follows.

      
    clear
    
    val = 0x01A0B0C0
    
    buff = Util.UIntToBytes(val)
    
    print "buff -> " + Util.BytesToHex(buff)
    
      


  3. Executed result is as follows.




3. Convert byte[] to value(ushort)
  1. You can convert byte[] into value by using below methods.



  2. Add script as follows.

      
    clear
    
    buff = Util.CreateArrayByte(2)
    buff[0] = 0x10
    buff[1] = 0x11
    
    val = Util.BytesToUShort(buff)
    
    print "val -> " + val
    
      


  3. Executed result is as follows.




4. Convert byte[] into value of uint type
  1. You can convert byte[] into uint typed variable by using below method.

       Util.BytesToUInt(byte[] buff)

  2. 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
    
      


  3. Executed result is as follows.