Convert Decimal to Base 8

Directions how to convert base 10 (decimal) to base 8 (octal).

Base 10 to Base 8

This document provides a quick example on how to convert decimal to base 8 (octal). There are two ways to convert base 10 to base 8. I am only showing the one of the methods. Wikihow has a nice tutorial. And cool conversion site provides a nice online calculator. For more information about modulo operations check out Wikipedia. You can also simply type '4242 to base 8' in Google. I also wrote this article to learn a bit about LaTex and how to write mathematical formulas in WordPress.

What is Base 8?

The decimal or base 10 number system has 10 digits. {0,1,2,3,4,5,6,7,8,9} Binary math is base 2 and only has the numbers 0 and 1. Base 8 or octal only has 8 digits. {0,1,2,3,4,5,6,7}

Here is a list of 8^0 through 8^5 just to see the first few exponents.

Base \ 8 = \ \begin{cases}  8^0=1 \\  8^1=8 \\  8^2=64 \\  8^3=512 \\  8^4=4096 \\  8^5=32769 \\  etc...  \end{cases}

Convert 4242 to Base 8 (Octal)

Follow the steps below to convert any decimal number to base 8. In this example I am converting 4242 to base 8.

  1. Divide \ (4242)_{10} successively by 8 until the quotient is 0. 
  2. The result is \ 4242/8 = 530.25. But only use the whole number of 530. Now find the remainder or the MOD of 4242. To do this use \ 4242-(8*530)=2. The remainder is 2 in this example. Or use MOD on your calculator. \ 4242 \bmod 8 = 2 
  3. Now take \ 530/8 = 66 and the MOD is \ 530 \bmod 8 = 2. Or use \ 530-(8*66)=2.
  4. Next take \ 66/8 = 8 and the MOD is \ 66 \bmod 8 = 2
  5. Next take \ 8/8 = 1 and the MOD is \ 8 \bmod 8 = 0
  6. Finally take \ 1/8 = 0 and the MOD is \ 1 \bmod 8 = 1

Here is the same example is a more legible format.

Division/8 Quotient MOD Octal
4242/8 = 530 MOD 2
530/8= 66 MOD 2
66/8= 8 MOD 2
8/8= 1 MOD 0
1/8= 0 MOD 1

Read the octal from the bottom to the top. The result is \ (10222)_8.

\ (4242)_{10} = (10222)_8

Convert Octal to Decimal

To convert base 8 (octal) to decimal write down the octal number and then multiply each digit by the corresponding power of 8 starting on the right hand side. Then add up the totals.

  1. Write down the octal
  2. Multiply each digit of the octal by the corresponding power of eight.
    1x8^4 + 1x8^3 + 6x8^2 + 1x8^1 + 1x8^0
  3. Solve the powers:
    1x4096 + 1x512 + 6x64 + 1x8 + 1x1
  4. Add up the numbers:
    4096 + 512 + 384 + 8 + 1
  5. The result in decimal is:

\ (11611)_8 = (5001)_{10}

ASCII Control Characters

List of ASCII control characters - Used by STTY and other UNIX items.

ASCII Characters

UNICODE has replaced ASCII in computers for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. However ASCII control characters are still sometimes used in STTY or in VI to remove carriage returns.

My usual 'CTRL-V+CTRL-M' didn't work for me on my DD-WRT home router to remove carriage returns from a text file. So I had to look up the alternatives yet again. I learned a new method sending OCTALS in SecureCRT. So I decided to to write down the basics in case I ever need to use some of the other control characters.

To see all of the ASCII settings go to This site will list the decimal, octal, hex, binary, & HTML number for each ASCII character.

The control character chart is copied below.

OCT DEC Char HEX CTRL KEY Description
\000 0 NUL \x00 ^@  \0 Null Byte
\001 1 SOH \x01 ^A Start of Heading
\002 2 STX \x02 ^B Start of Text
\003 3 ETX \x03 ^C End of Text
\004 4 EOT \x04 ^D End of Transmission
\005 5 ENQ \x05 ^E Enquiry
\006 6 ACK \x06 ^F Acknowledge
\007 7 BEL \x07 ^G Ring Terminal Bell
\010 8 BS \x08 ^H  \b Backspace
\011 9 HT \x09 ^I  \t Horizontal Tab
\012 10 LF \x0A ^J  \n Line Feed (New Line)
\013 11 VT \x0B ^K Vertical Tab
\014 12 FF \x0C ^L  \f Form Feed
\015 13 CR \x0D ^M  \r Carriage Return
\016 14 SOH \x0E ^N Shift Out
\017 15 SI \x0F ^O Shift In
\020 16 DLE \x10 ^P Data Link Escape
\021 17 DC1 \x11 ^Q Device Control 1 (XON)
\022 18 DC2 \x12 ^R Device Control 2
\023 19 DC3 \x13 ^S Device Control 3 (XOFF)
\024 20 DC4 \x14 ^T Device Control 4
\025 21 NAK \x15 ^U Negative Acknowledge
\026 22 SYN \x16 ^V Synchronous Idle
\027 23 ETB \x17 ^W End of Transmission Block
\030 24 CAN \x18 ^X Cancel
\031 25 EM \x19 ^Y End of Medium
\032 26 SUB \x1A ^Z Substitute Character
\033 27 ESC \x1B ^[ Escape
\034 28 FS \x1C ^\ File Separator
\035 29 GS \x1D ^] Group Separator
\036 30 RS \x1E ^^ Record Separator
\037 31 US \x1F ^_ Unit Separator (CTRL-Underscore)
\177 127 DEL \x7F ^? Delete

Remove Carriage Returns (^M)

Brief tutorial on how to remove carriage returns in UNIX. Use CTRL-V+CTRL-M in SED or VI. Use octal \026 \015. Use tr or perl.


Whenever you transfer files from DOS (Windows) to UNIX boxes it is possible that carriage returns may be added to your text files.  This will sometimes prevent the file from working properly in UNIX.  I have actually had some files work with carriage returns (CR hex 0D).  I know the simple VI command to remove the carriage returns (^M) at the end of each line. And there are several other ways to remove carriage returns.

I ran into a problem on my home router running DD-WRT. It would not allow me to type CTRL-V+CTRL-M to create the carriage return (^M) in vi or anywhere else. I suspect is a busybox shell issue. So I had to find another way. This document shows the standard methods as well as a new method I used on my router. I am not including 'dos2unix' and 'unix2dos' as these may not by installed. I prefer to remember standard methods that should work on all boxes without installing additional software.

Who Uses What

A brief rundown on which OS uses which symbol for a line terminator.

  • LF = linefeed (move cursor down) - CTRL-J / ^J / hex 0A / Sometimes written as NL (newline)
  • CR = carriage return (return cursor to left margin) - CTRL-M / ^M / hex 0D
  • UNIX = LF only
  • DOS = CRLF (each line ends with CR then LF)
  • MAC = CR only

Typing ^M

To create the return character in vi or the command line you normally type "CTRL-V+CTRL-M". That is you press and hold the control key and then press 'v' and then 'm' (without the single quotes) and then release the control key. Another way is to use '\r'. (backslash r) And one more way is to use octal. Type '\026' for 'CTRL-V' and '\015' for 'CTRL-M'.

The Commands

Below are the various methods to edit the file. There are more methods than listed here. One of these is likely to work.


The percent sign (%) will perform the search and replace on all lines. And the 'g' at the end does the search and replace globally and not on just the first instance in the line.


Other ways to accomplish the same task.


This wiki article has some other useful tidbits about VI (VIM) and file formats.

Display the fileformat option (ff) for the current buffer, and the fileformats global option (ffs) which determines how VIM reads and writes files.

:set ff? ffs?
:verbose set ff? ffs? (Helps to see in your vimrc)

Convert from dos/unix to unix

:update             Save any changes
:e ++ff=dos         Edit file again using dos FF (fileformats                                  ignored)
:setlocal ff=unix   This buffer will use LF only
:w                  Write buffer using unix (LF-only) line endings

Convert from dos/unix to dos

:update             Save any changes
:e ++ff=dos         Edit file again using dos FF (fileformats                                  ignored)
:w                  Write buffer using unix (LF-only) line endings

tr (translate)

The '-d' flag deletes the tokens. Input the original file and output the new file. The '\r' (slash r) is another way to type the carriage return.

tr -d '\r' < file > newfile


Search and replace using sed is quite common. You can type ^M various ways. I am showing three methods. The '-e' is for scripting on the command line and running those commands directly. The greater than sign (>) redirects the output to a new file. Otherwise the results are just displayed to stdout (standard out). You can add a 'g' to the end for global replacement just like in vi. The '-r' is for using regex (regular expressions).

sed -e 's/\r//' file > newfile

sed -e 's/^M//' file > newfile

sed -r $'s/\026|\015//g' file > newfile


You can also use a one line perl command. The '-e' is used to enter one line of script to be run by perl. Multiple '-e' commands may be given. The '-p' causes perl to assume a certain type of loop command. Useful for one liner commands. The '-i(extension)' will edit the file in place. The extension is added to the filename. The original file is saved as 'filename.extension'. The edited file is saved as the original filename.

perl -pi.bak -e 's/\r//g' filename

OTT TV Comparison

My comparison of three OTT (Over the Top) TV providers. I compare Sling TV, Playstation VUE, and Youtube TV.

OTT (Over the Top) TV

OTT, Over the Top, TV is streaming TV.  All you need is an internet connection.  I started using Sling TV a few years ago.  Today I am using Playstation VUE (PS VUE).  I have also tried Youtube TV.  I may try DirecTV Now in the future. Fortunately all of these new TV providers allow you to try them for free. This article covers three OTT TV providers.

Channel Lineups

Playstation VUE has 4 different lineups.  Each one is more expensive and includes more channels.  Today Youtube TV only has one channel lineup. Sling TV has 2 channel lineups.  You can purchase either one or both with a $5 discount.  This link below will take you to a Google Sheets spreadsheet that compares all of the lineups in the Chicago area.  Keep in mind different markets will have different channels.  And each company may add or subtract channels at anytime.  More about the channels is mentioned below.

Points to Consider

There are a number of things to consider about each OTT TV provider. My comparison is of the Chicago lineups. Here is my list.

Over the Air TV

Not all providers have your local ABC, CBS, NBC, and FOX stations.  Some only have on-demand versions of these stations.  The on-demand versions probably don't allow you to fast forward through commercials. But I have the actual stations and not on-demand so I cannot be %100 sure of this statement. Some provide Telemundo and the CW. PS VUE has My Network, but that is probably the CW as it changed in Chicago from My Network to the CW. But I never watch the station so I don't know for sure. None of the providers have PBS. But PBS is government run so it will probably never be available.

  • PS VUE - Has all four major networks. Plus it has Telemundo and My Network/CW.
  • Youtube TV - Has all four major networks and the CW.
  • Sling TV - On-demand versions of NBC and FOX are available if you buy the blue plan.

Cloud DVR

PS VUE and Youtube TV both offer a cloud DVR.  Sling TV is supposed to be adding this feature. You can record as many shows as you like. Youtube TV will keep your recordings for 9 months while PS VUE will only keep your shows for 28 days.


Live sports is the biggest draw for cable and OTT TV is a very good alternative. Youtube TV is actually geared for sports and offers the most sports stations for the lowest price. But Youtube TV does not offer TNT or TBS. Without these stations you may miss some baseball and NBA playoff games. Local blackout rules still apply. Also I ran into a couple of games where the station did not have the rights to stream the game over the internet. In one instance I was able to find the game on another channel. In the other instance I didn't look for the game on other channels. It may have been available. But this is ridiculous and annoying that I may not be able to watch a game just because I am using OTT TV.

Your local sports channels will vary greatly from city to city.

News Networks

Let's face it, there isn't enough news for a 24/7 news channel. Let alone 7 or more 24 hour news channels. They all bloviate ad nauseam. Youtube TV does not have CNN. And it only has a few news stations. I prefer to read the BBC World News. Or I could simply watch it on the BBC via VPN.

Website / App Access

I like the ability to sign into a station website or application. It is one way to catch up on series that are not available via on-demand from your OTT TV provider.

  • PS VUE - It seems I can sign into any TV channel to which I subscribe. The only exception I found was CSN (Comcast Sports Network). This channel doesn't seem to allow any OTT TV provider. Seeing as it is owned by Comcast, the most despicable company in the USA, I am not surprised.
  • Youtube TV - It doesn't appear any channel allows logins for Youtube TV.
  • Sling TV - When I used this service before I could only log into ESPN. It seems a few more stations are available today. But not all of them.

Watch on Which Devices

You can watch all of the providers on IOS (Apple) and Android devices. You can watch all of the providers on your computer. And you can watch all providers on your TV. However, Youtube TV only works with Chromecast on your TV. I prefer Roku when I am watching TV recordings so I can easily skip the commercials with a remote and not open my tablet.

Premium Movie Channels

You can always buy HBO and Showtime separately if you like. Check the channel lineups at each site to see which movie channels you may purchase. These channels are usually separate add-on channels purchased separately.

Remote Access Away From Home

There are limitations as to which channels are available on your tablet if you are away from home. These limitations are complicated and stupid. Although I want to check to see if I can access everything on PS VUE if I use a VPN to my home router.

Concurrent Streams

This option is more important in a family. But even as a single person I sometimes watch multiple streams at the same time.

  • Sling - Sling Orange only has one stream.  Sling Blue has 3 concurrent streams. And if you buy both plans you will have 4 concurrent streams.
  • PS VUE - You can have 5 separate accounts on PS VUE.  This provides a total of 5 concurrent streams total.  One user can have up to 5 streams.
  • Youtube TV - You can have 3 concurrent streams.  You can have 6 accounts, but only 3 people can watch at the same time.


Which service is best for you really depends on which channels you want to watch. Decide if you need the local over the air channels and if you need a DVR.

At this time I plan to stick with PS VUE. But what I truly want is totally a la carte TV. I suspect a lot of channels would disappear if people were not forced to purchase these useless channels.