1
$\begingroup$

Binary numbers like '0110', or '00100101' are seen very often in all contexts. What are the leading (left hand side) zeroes for? Why did the writer not write '110' and '100101', respectively?

$\endgroup$
2
$\begingroup$

Leading zeroes in binary usually indicate the bit length of the data type. For example, the number 110 represented in a 4 bit data type would be 0110. Even if there is no data type specified, it's sometimes common to pad your binary numbers to the next power of 2. For example, 10111 of size 5 should be padded to 8 $(2^3)$ as 00010111

$\endgroup$
1
  • $\begingroup$ You wrote: "Even if there is no data type specified, it's sometimes common to pad your binary numbers to the next power of 2." What is the rationale for doing that? $\endgroup$ Apr 12 at 18:09
1
$\begingroup$

Depend on context, so, I bring one small example: if we consider $3$-bit field, then $110$ is negative in $2$'s complement and equal $-2$, while in $4$-bit field $0110$ is positive and equal $6$ in same $2$'s complement.

$\endgroup$
2
  • $\begingroup$ What makes 110 negative? The leading '1'? $\endgroup$ Apr 11 at 13:48
  • $\begingroup$ Yes. In $2$'s complement all binary code with leading bit $1$ is negative. $\endgroup$
    – zkutch
    Apr 11 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.