The PHP programming language has many built-in functions for converting numbers from one base to another. In fact, it has so many functions that it can be hard to know which to use. Some functions have similar capabilities, and some work with parameters of different types. We’ll sort through the differences in this article, and explain the proper context in which to use each function.
The Pioneer 10 (also known as Pioneer F) spacecraft, launched in 1972 and now on a very long journey towards Taurus, has a plaque mounted on it which is designed to inform alien civilizations about the spacecraft’s origin. The plaque contains a diagram of our solar system, the trajectory of the spacecraft, a drawing of a man and woman, and groups of vertical and horizontal strokes — you guessed it, binary code — that gives information about how to find us:
Did you know you can use the calculator with numbers in different bases? It can convert numbers between decimal, binary, hexadecimal, and octal, as well as do arithmetic in those bases. To work in a non-decimal base, just prefix numbers as follows: 0b for binary, for example, 0b1010; 0x for hexadecimal, for example, 0xFF; and 0o for octal, for example, 0o701.
My son had to do a project for his 100th day of first grade. Since I’ve been teaching him binary — he knows the powers of two from 1 to 512 — we decided to incorporate it into his project. His assignment was to assemble 100 objects in a creative way. This is as creative as I get:
The Binary Marble Adding Machine is a device that adds binary numbers mechanically. It uses wood instead of silicon, gravity instead of voltage, and marbles instead of current. We don’t need no stinkin’ CMOS!
The machine may be more cool than practical, but it certainly is educational. It illustrates basic principles of binary numbers, binary arithmetic, and binary logic. Let’s take a closer look.
What is a binary clock? Before doing a web search I would have guessed this:
In other words, a regular digital clock, except with binary numerals instead of decimal numerals. But as far as I know, a clock like this doesn’t exist. If you search for “binary clock,” you get a clock of a different design, one like this: