Thread: why are octal and hexadecimal numbers written the way they are?

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    228

    Question why are octal and hexadecimal numbers written the way they are?

    Now, I know how to represent decimal numbers in octal and hexadecimal notation and can seamlessly convert from one number system to another with no problem, but what I want to ask is what is the purpose of writing decimal numbers like 8 with a zero in the octal system like this: 010 and a 0x in the hexadecimal system like: 0x8 ?

    Was it for convenience sake or to simply differentiate each number system from each other? Is there a historical reason for it?

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Was it for convenience sake or to simply differentiate each number system from each other?
    I would think, both. Programming language are generally flexible with given values, and a quick and easy way to distinguish base would be a boon.

    For instance, the number "11" might mean several things depending on the base.

    112 = 3
    118 = 9
    1110 = 11
    1116 = 17

    Sometimes, you want to use values as decimal, since this is the most common way we experience numbers in our lives (which is probably why this is the "default" interpretation of numbers).

    Sometimes, you want to use binary or hexadecimal since this is the neatest way to deal with an array of bits.

    Octal has its own niche where it is more convenient to use.

    Is there a historical reason for it?
    I'm no expert on these things, and perhaps someone else here can give you better answers to this question, but you can find some quick background on wikipedia:

    Quote Originally Posted by wikipedia
    Several different notations are used to represent hexadecimal constants in computing languages; the prefix "0x" is widespread due to its use in Unix and C (and related operating systems and languages)
    Hexadecimal - Wikipedia, the free encyclopedia

    Quote Originally Posted by wikipedia
    In programming languages, octal literals are typically identified with a variety of prefixes, including the digit 0, the letters o or q, or the digit–letter combination 0o. In Motorola convention, octal numbers are prefixed with @, whereas a small letter o is added as a postfix following the Intel convention. DR-DOS DEBUG uses \ to prefix octal numbers.
    Octal - Wikipedia, the free encyclopedia
    Last edited by Matticus; 05-08-2015 at 07:04 PM.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    228
    Thanks for taking the time to answer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Decimal, Octal & Hexadecimal
    By mie2cpr in forum C Programming
    Replies: 2
    Last Post: 03-01-2011, 10:56 AM
  2. hexadecimal numbers
    By Sonia in forum C Programming
    Replies: 37
    Last Post: 11-24-2010, 10:14 PM
  3. Hexadecimal Numbers etc?
    By sharkbate24 in forum C++ Programming
    Replies: 6
    Last Post: 12-30-2008, 04:00 PM
  4. octal numbers
    By firefly in forum C++ Programming
    Replies: 4
    Last Post: 07-13-2005, 06:24 AM
  5. binary/octal/hexadecimal
    By razrektah in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2001, 06:33 PM

Tags for this Thread