Advertisement
Guest User

byteA2LongA

a guest
Nov 1st, 2012
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. long * byteA2LongA(byte * byte_slice, long * ret_array){
  2.   /**
  3.     * Convert the retrieved bytes into a set of 32 bit longs
  4.     **/
  5.     //varibale that stores the addressed long to be stored in sram
  6.     long currentLong;
  7.     int sizeOfB = sizeof byte_slice / sizeof(byte);
  8.     int sizeOfL = sizeOfB / 4;
  9.     if(sizeOfB % 4 != 0) ++sizeOfL;
  10.         for(int i = 0; i < sizeOfB; i+=4){
  11.             currentLong = 0;
  12.             if(byte_slice[i]=='\0'){break;}
  13.             if(i + 3 < sizeOfB)currentLong = (currentLong << 8) + byte_slice[i+3];
  14.             if(i + 2 < sizeOfB) currentLong = (currentLong << 8) + byte_slice[i+2];
  15.             if(i + 1 < sizeOfB) currentLong = (currentLong << 8) + byte_slice[i+1];
  16.             currentLong = (currentLong << 8) + byte_slice[i+0];
  17.             ret_array[i] = currentLong;  //Serial.print("CurrentLong:  ");
  18.         }
  19.         //pointer to the retrn array in the parent scope
  20.         return ret_array;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement