PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 12, 2022

[FIXED] How to convert Binary to Decimal and Octal?

 August 12, 2022     binary, data-conversion, decimal, octal     No comments   

Issue

I have a BINARY number which i want to convert it into the DECIMAL and OCTAL.

(0100 1111 1011 0010)2

I know how to convert it into the decimal. But the question making me confuse. Because middle of every 4 digits there is a space "0101 1111" can u help me how to understand this question.

Thanks


Solution

First of all, make sure that number you are converting into Decimal and Octal is actually 'Binary' and not 'Binary Coded Decimal (BCD)'. Usually when the number is grouped into 4 binary digits, it represents a BCD instead of just binary.

So, once you make sure its actually binary and not BCD, the conversion to both decimal and octal are simple steps.

For binary to octal, you group the binary number into sets of 3 digits, starting form the Least Significant Bit(LSB or right-most) to the Most Significant Bit(MSB or left-most). Add leading zeros if a group of 3 digits can not be formed at the MSB.

Now convert each group of digits from binary to octal:

(000) -> 0 (001) -> 1 . . (111) -> 7

Finally put the numbers together, and there you have your binary converted to octal.

Eg:- binary - 00101101 split into groups of 2: -> 000 101 101 -> 0 5 5 - > 55

Difference between'Binary Coded Decimal' and 'Binary':

For the decimal number 1248 the binary would simply be 10011100000 However, the BCD would be -> 0001 0010 0100 1000



Answered By - Rct Lynx
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing