c++ - convert 512-bits in a 256 Hexadecimal table -


i have buffer unsigned char table[512] want convert faster table of short int table[256] every position compound bytes of table.

i have camera give me buffer table convert disparity real depth.

unsigned char zdtable[512] = {0}; unsigned short int zdtablehexa[256]={0}; .. buffer data..... (int = 0; < 256; ++i) {         zdtablehexa[i]=zdtable[i*2]<<8 + zdtable[i*2+1];  } 

these 2 has problem in converting values, bytes inversed:

memcpy(zdtablehexa_ptr,zdtable,256*sizeof( unsigned short int)); unsigned short* zdtablehexa = (unsigned short*)zdtable; 

try

short* zdtablehexa = (short*)zdtable; 

it maps memory space of char array array of shorts. if memory looks this: (char0),(char1),(char2),(char3)

then reinterpreted be
(short0 = char0,char1),(short1 = char2,char3)

beware such direct reinterpretation depends on endianness , formally allows sufficiently pedantic compiler ungood things, i.e., it's system- , compiler-specific.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -