DEV Community

Cover image for Unit Conversion Explained: Length, Weight, Temperature and Binary
Moksh Gupta
Moksh Gupta

Posted on Originally published at devtoollab.com

Unit Conversion Explained: Length, Weight, Temperature and Binary

Conversion errors are rarely dramatic. They are a decimal point in the wrong place, a value entered in inches while the dropdown still says centimeters, or a temperature converted with a multiplier and no offset. The arithmetic is easy, which is exactly why people stop checking it.

This is a shorter, code-flavored take on a piece I published on DevToolLab. If you want the plain-language version with more everyday examples and none of the JavaScript, the original is here.

What Conversion Actually Changes

A conversion changes how a quantity is written down. It does not change the quantity.

Two meters and two hundred centimeters describe the same table. One meter contains one hundred centimeters, so moving between the two units is a single multiplication. The table did not grow. Only the label did.

That distinction matters because it tells you what a correct answer should look like before you calculate it. If you convert into a smaller unit, you should end up with a bigger number. If you do not, stop and look at what you typed.

Where It Bites in Practice

Units diverge by country, by industry, and sometimes by team. Furniture listed in inches when you think in centimeters. A recipe in cups when your scale reads grams. An API returning Fahrenheit when your dashboard renders Celsius.

The professional cases are the expensive ones. Engineers, architects, technicians and scientists move between systems constantly, and a conversion slip propagates quietly into every calculation downstream of it. Nothing errors. The number is simply wrong.

Length and Weight: Multiply and Move On

Most length and mass conversions are one multiplication because the units share a zero point. A few relationships cover most of what you will meet:

  • 1 meter = 100 centimeters
  • 1 kilometer = 1,000 meters
  • 1 foot = 12 inches
  • 1 yard = 3 feet

Mass works the same way. Kilograms, grams and milligrams sit in the metric system, while pounds and ounces remain standard in the United States, so shipping, cooking and product specs are where the two systems usually collide.

Temperature Is the Exception

Temperature scales do not share a zero, so a multiplier alone will not get you there. Celsius to Fahrenheit multiplies by 9/5 and then adds 32. Skip the offset and every answer is wrong by 32 degrees.

const toF = (c) => (c * 9) / 5 + 32
const toC = (f) => ((f - 32) * 5) / 9

console.log('20C  ->', toF(20) + 'F')
console.log('98.6F ->', toC(98.6).toFixed(1) + 'C')
Enter fullscreen mode Exit fullscreen mode
20C  -> 68F
98.6F -> 37.0C
Enter fullscreen mode Exit fullscreen mode

Celsius is the international default, Fahrenheit is standard in the United States, and Kelvin is what you use in scientific work because its zero is absolute rather than arbitrary.

Decimal, Binary and Powers of Two

Not every conversion involves something physical. Decimal gives you ten digits, 0 through 9. Binary gives you two, 0 and 1, which is what hardware actually stores.

The mapping stops feeling strange once you see it as powers of two rather than as a lookup table. Decimal 10 becomes 1010 because 10 equals 8 plus 2.

console.log('10 in binary    ->', (10).toString(2))
console.log('1010 in decimal ->', parseInt('1010', 2))

for (const n of [1, 2, 5, 10, 255]) {
  console.log(String(n).padStart(3), '=', (n).toString(2).padStart(8, '0'))
}
Enter fullscreen mode Exit fullscreen mode
10 in binary    -> 1010
1010 in decimal -> 10
  1 = 00000001
  2 = 00000010
  5 = 00000101
 10 = 00001010
255 = 11111111
Enter fullscreen mode Exit fullscreen mode

That last row is worth memorizing. Eight ones is 255, which is why a single byte tops out there and why so many limits in computing land on that number. If you want to poke at other bases without writing the loop, the Number Base Converter handles binary, octal, decimal and hex in one place.

By Hand or With a Tool

Doing a conversion manually is the better way to learn one, because the formula is the part you actually need to retain. Reach for a tool when the work is repetitive, the numbers are awkward, or the units are ones you rarely touch and would have to look up anyway.

The failure mode with tools is not the math, it is the input. A tool will faithfully convert a value you entered under the wrong unit and hand you a confident, wrong answer. The Temperature Converter is the kind of thing worth using precisely because the offset is easy to forget, but you still have to select the right scale.

The longer version on DevToolLab goes further into when manual conversion is genuinely worth the effort.

Five Habits That Prevent Wrong Answers

  1. Name both units before you start. Write down what you have and what you want. Most errors happen because that was never made explicit.
  2. Check whether you need a factor or a formula. Meters to centimeters is a factor. Celsius to Fahrenheit is a formula. Treating the second like the first is the classic mistake.
  3. Watch the decimal point. A single misplaced digit changes the result by an order of magnitude and still looks plausible.
  4. Estimate first. Five kilometers in meters should be in the thousands. If your answer is smaller than five, something went wrong before the arithmetic did.
  5. Re-read the unit selectors. When using a converter, confirm the source unit as carefully as you check the value.

Why It Keeps Coming Up

You do not need to work in a lab for this to matter. Resizing furniture, scaling a recipe, reading a spec sheet, comparing distances, or parsing an API that reports in units your frontend does not use are all the same skill.

Students hit it constantly too, since math, physics, chemistry and computer science problems tend to fail on units well before they fail on method.

Wrapping Up

Conversion comes down to knowing the relationship between two ways of writing the same thing. Length and mass are usually one multiplication. Temperature needs an offset as well. Number bases are the same idea applied to how a value is represented rather than what it measures.

Learn the relationship, pick the right factor or formula, and sanity-check the magnitude of the answer. That last step catches almost everything the first two miss.

References

Top comments (0)