c++ - Rotating left is rotating right -


in c++ want rotate array of 4 characters once left using assembly instruction rol. thought i'd interpret array dword , rotate dword once left , wanted. instead, whenever rotate dword once left it's rotating once right. asm code:

shiftrow proc ; copy array eax mov eax, dword ptr [rcx] rol eax, 8 mov dword ptr [rdx], eax ret shiftrow endp 

and how c++ code looks like:

#include <iostream> using namespace std;  extern "c" void __fastcall rotatearray(const char* array, char* outputarray);  int main() {     char input_array[] = {0x10, 0x20, 0x30, 0x40};      char output_array[4] = {};     rotatearray(input_array, output_array);       for(int = 0; < 4; i++)         std::cout << std::hex << (unsigned int)output_array[i] << " ";     cin.get(); } 

strangely enough (to me) output 40 10 20 30 though shifting left. can explain me why happening? have endianness?

yes, due endianness, , machine little-endian machine. happening:

input_array before rotation: 10, 20, 30, 40

eax before rotation : 40 30 20 10

eax after rotation : 30 20 10 40

output_array after rotation : 40, 10, 20, 30


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -