Do any of the operations dealing with masking or extracting individual bits from an integer depend on endianness? I’ve written some code, but with access only to hardware of one type, I can’t really check that its operators are endian-independent. Please let me know if you see any bugs. NOTE: This code was written for a homework problem, and personal edification:
void PrintDecimalIntegerInBinary (long long n)
{
PrintDecimalInBinaryRecursion(n, n >= 0);
}
void PrintDecimalInBinaryRecursion (long long n, bool sign)
{
if (n == 0) {
cout << (sign ? 0x0 : 0x1);
}
else {
PrintDecimalInBinaryRecursion((unsigned long long)n >> 1, sign);
cout << (n & 0x1);
}
}
Thanks for your help.
Endianness only determines how data is stored, not how it’s processed. So any bitwise operators or bit shifting are unaffected by endianness. Specifically,
0x1means the same thing regardless of the endianness.