Elementary binary question

So I was trying to make a joke with my son about binary (admittedly an error on my part) and then I got confused. Does the binary sequence go 0, 1, 00, 01, 10, 11 or does it go 0, 1, 10, 11, 100, 101, 110, 111??? In other words, can binary use leading zeros? I am pretty sure the proper sequence is the second one but I am not sure why. I know we don’t use leading zeros. Are binary zeros exactly the same as decimal zeros?

Yes. It would use leading zeroes only in the same case we would decimally. For example if there was a counter with a certain number of dials all set to zero originally like the odometer on a car.

The second sequence is correct.

Leading zeros are important in BCD format.

As **OldGuy ** has said, the second sequence is correct. Each digit in binary represents a multiple of 2[sup]0[/sup], 2[sup]1[/sup], 2[sup]2[/sup] etc in the same way that they represent 10[sup]0[/sup], 10[sup]1[/sup], 10[sup]2[/sup] etc in decimal.

So 111 in binary
= (1 x 2[sup]2[/sup]) + (1 x 2[sup]1[/sup]) + (1 x 2[sup]0[/sup])
= 4 + 2 + 1
= 7

Like others have said, leading zeroes behave just like you would expect them to in decimal. There’s a bit of a wrinkle, though, because computers operate in binary and they can’t deal with variable length numbers. To the computer I’m typing this on right now, every number consists of 32 digits. Leading zeroes are just a fact of life here.

Does anyone use BCD anymore?

Most hardware that does signed arithmatic uses 2s compliment representation for the numbers. 2s compliment representation uses n bits to encode -(2^n) to (2^n -1). The nth bit is valued at -(2^n). So if you want to count natural numbers you can omit the leading zeros but if the value can be negative then leading zeros matter.

Is 111 7 or is it -1?

You do use leading zeros for “floating point” binary numbers:

on the left side of the “binary point”, each digit is worth 2[sup]0[/sup], 2[sup]1[/sup], as Cunctator said. On the right side, each digit is worth 2[sup]-1[/sup], 2[sup]-2[/sup], etc.

For example,

0.5 = 0.1
0.75 = 0.11
0.125 = 0.001

3.14159 = 11.0010010000110…

For numbers with a binary point, the leading zeros matter just like with decimal numbers.

Arjuna34

PS - lets not get into whether 1.0 = 0.1111111… binary!

Binary per se does not have to use leading 0s, so your second choice is correct. If you are representing the contents of storage of a certain size (which does not have to be the native word size of a computer) then you would use leading 0s. And not just for binary - hex also.

A 32 bit binary word of

0000000111111010
would be
01fa in hex.
Same for octal, and any other base you’d choose.

Incidentally, “121” in any number base (bigger than binary, of course) is a perfect square, representing as it does: x[sup]2[/sup] + 2x + 1 = (x+1)[sup]2[/sup].

Thus, in decimal, 121 = 11[sup]2[/sup]
Hexadecimal 121 = 289 decimal = 17[sup]2[/sup]
Octal 121 = 81 decimal = 9[sup]2[/sup] and so forth.

1331 is always a cube, too.

If it interests you much, you can get a binary clock. Coincidentally, the place where I work just hired a new employee, and he brought one of these to work last week.

Yes. For example:

Internally, within a computer, you mean? Probably not much.

Yes. Most handheld calculators use BCD arithmetic. It’s also widely used in business applications and hardware-constrained systems that display/print numbers.

Mike Cowlishaw from IBM is probably the world’s top expert on decimal arithmetic. See http://www2.hursley.ibm.com/decimal/ for everything you ever wanted to know about decimal arithmetic.

Quoth Bryan Eckers:

More to the point, 121 = 11[sup]2[/sup] and 1331 = 11[sup]3[/sup] in every bases where those numbers are defined. 121(hex) = 289(dec), and 11(hex) = 17(dec). It’s also true that 100 = 10[sup]2[/sup] in every base, 14641 = 11[sup]4[/sup], and 15aa51 = 11[sup]5[/sup].

And pascal’s triangle strikes again. :wink:

Quite aside from the leading-zeroes question, how could “00” ever follow “1”?

It’s not how binary works, but I see what Leibowitz was thinking. 00 follows 1 because 1 is the largest single binary digit, while 00 is the smallest string of two binary digits.

In other words, in this ordering we first have the single digits:

0
1

Then we have the binary strings with two digits:

00
01
10
11

Three digits:

000
001
010
011
100
101
110
111

Next come all the four digit sequences, and so on.

It’s a well-defined order on the set of all finite strings of binary digits, but it’s not the standard one.

Not standard for arithmetic, perhaps, but that sort of ordering is very convenient in proofs that certain sets (notably, the set of finite-length binary strings) are countable.

To be pedantic, that’s because the "standard"one isn’t really an order on the set of finite binary strings, it’s an order on the set of nonnegative integers. Which happen to be expressed in binary notation.