Daniele Esposti's Blog

Detect if a number is power of 2

Easy post today: simple method to detect if a number is a power of 2 in O(1) complexity. Yes, O(1), no naive loops involved :-). The code is very simple: bool powerof2(unsigned int n) { return n > 0 & !(n & (n - 1)); } The code looks cryptic,...


Cross-compile 64-bit code on 32-bit machine

Now that I have a spare machine where I can do all my experiments, I can start again to write posts about Disassembly C code for fun but, wait, my current hardware is a 32-bit Pentium-M CPU and I want to build and disassembly 64-bit code! Let’s set up my...


Install Ubuntu without PAE support

Last night I brought to a new life my old laptop to be used during my commuting time to write posts, to experiments some technologies and last but not least show how old hardware can be recycled and used efficiently. With my great surprise I discovered most of the 32-bit...


Hamming weight's Python implementation

Counting the number of 1’s in a binary representation of a number (aka Hamming weight aka popcount when binary numbers are involved) with Python using different implementations (naive implementations are obviously excluded :-) ). Implementation and benchmarking To compute the Hamming weight of a number in binary representation two implementations...


Disassembly C code for fun – Part 7: buffer overflow protection

Originally this article was about strings but as soon as I disassembled the first C test code I saw an interesting bit of assembly code so I switched the topic: today we will talk about buffer overflow protection and the canary (obviously I’m not talking about the little bird but...