Urgent.News

What's breaking now, across thousands of outlets.

Tech

Binary, Octal, Decimal, and Hexadecimal Explained (With Conversion Methods)

We write numbers in base 10 because we have ten fingers. Computers work in base 2, and programmers often use base 8 and base 16 as compact ways to write binary. Once you see the pattern, conversions become straightforward. What a base means In any base, each digit position is worth a power of the base. In decimal, 345 means 3 x 100 + 4 x 10 + 5 x 1. In binary, each position is a power of 2, so…

Numbers are represented in base 10 due to our ten fingers. Computers use base 2, while programmers frequently employ base 8 and base 16 for compact binary representation. Understanding the pattern behind bases simplifies conversions.

In any base, each digit position holds a power of the base. For example, decimal 345 equals 3 x 100 + 4 x 10 + 5 x 1. Binary positions are powers of 2, so 1101 represents 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1, equating to 13. There are four standard bases: binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16).

Binary utilizes digits 0 and 1, mirroring hardware storage. Octal uses digits 0 to 7, common in Unix file permissions (chmod 755). Decimal employs digits 0 to 9 for everyday numbers. Hexadecimal blends digits 0 to 9 and letters A to F for colors, memory addresses, and byte values.

To convert decimal to another base, divide the number by the target base, record the remainder, and repeat until the quotient is 0. Read remainders from last to first. For example, 255 in hexadecimal: 255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15. Both remainders are F, so 255 is FF in hex.

Hexadecimal is prevalent because one hex digit equals four bits, making one byte always two hex digits. This explains color representation like #4338ca and the byte value 0xFF as 255. Binary-to-hex conversion involves grouping bits in fours. In code, binary is prefixed with 0b, octal with 0o, and hex with 0xFF. JavaScript's parseInt() parses hex, while toString(2) converts to binary. Python's int(), bin(), oct(), and hex() functions perform conversions.

Negative numbers are stored in two's complement form, altering values based on sign. Use type checks when converting negatives. Hexadecimal's widespread use stems from its ability to compactly represent binary values.

To convert binary to decimal, sum the powers of 2 for each 1 bit. Binary 1101 equals 8 + 4 + 1 = 13. Hexadecimal is favored by programmers for its compact representation of binary data. 255 translates to 11111111 in binary and FF in hexadecimal. The chmod 755 command uses octal permission values: 7 for owner (read, write, execute) and 5 for group and others. Explore conversions with the free, browser-based Number Base Converter, available at ilovekit.app.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

OpenNVR 0.1.6 Is Out: Search Your Camera Footage in Plain English

What if you could search hours of CCTV footage by simply describing what you're looking for? Instead of manually scrubbing through recordings, imagine searching for "red truck at the dock yesterday"…

  • OpenNVR 0.1.6 released with AI-powered video surveillance enhancements
  • Natural language search for CCTV footage using keywords, colors, vehicle types
  • Integration with Home Assistant via MQTT discovery and enhanced security

How to Avoid YouTube Ads Using MikroTik and a VPN

I do not watch YouTube that often, but the ads get on my nerves whenever I do. For a while, I paid for Turkish YouTube Premium through my Apple account.

  • Set up VPN connection on MikroTik router using IKEv2/IPsec protocol
  • Configure MikroTik router with VPN provider's certificate and IPsec settings
  • Route YouTube traffic through VPN by importing IP ranges and setting firewall rule

More from Sunday 11 October →