if I have in c++:
char abc[4];
abc[0] = 0xC0; //11000000 in binary
abc[1] = 0x20; //00100000 in binary
abc[2] = 0x44; //01000100 in binary
abc[3] = 0x20; //00100000 in binary
So how this will be stored in memory –
11000000 00100000 01000100 00100000 or the reverse way ??
-----------------------------------
0th 1st 2nd 3rd
In Java I am creating Bitset abc = new Bitset(32);
So I need to store the same values in this(same order).This may be
modified later according to bit positions so have to be exact same way.
So abc[32] = 0xC0204420 will do? And if I want to store
the values in c++ way what to do??
If I am wrong then how to do this in Java…
Endian is not an issue. If you use
char[4]the lowest address 0 will be first, the highest 3 will be last, so you get in memorywhatever you do.
If you do a
int x = *(reinterpret_cast<int*>(abc)), then you get different results, depending on endianness, because the (4byte-)intis sometimes read as0123, sometimes3210— and I think even2301has been around in the 60s.You can not put
0xC0204420(a larger number then127) into the[32]ths position ofabc. If you want to implement something “fast” (and dangerous) you would need a platform-dependingreinterpret_cast. Take a look athtonandntoh.