2

I have an array of bytes (char1) and I have to go through converting them to specific data types. For example the first two bytes in the array need to be converted to ascii characters so I just cast them using

    c = string(char1[0])

but for char1[2] and char1[3] I need a 16bit unsigned integer so how would I go about combining those two bytes and casting them as uint? I'm looking for a general answer as I will need to convert to types ranging from 1 byte up to 8 bytes.

Thanks

4

2 に答える 2

2

uint使用するルーチンです。試す:

IDL> b = bindgen(2) + 1B
IDL> print, b
   1   2
IDL> ui = uint(b[0:1], 0)   
IDL> print, ui
     513
IDL> print, 2^9 + 2^0
     513
于 2012-12-14T17:12:04.857 に答える
1

機能しない理由i = uint(char1[2] + ishft (char1[5], 8))は、シフトされる変数が byte であり、8 だけシフトするとオーバーフローするためです。代わりに、シフトを行う前に uint に変換します。

i = uint(char1[2]) + ishft(uint(char1[3]),8)
于 2013-01-16T21:40:02.107 に答える