A guide to binary, decimal conversions

  • Thread starter Magna Visus
  • Start date
  • Tags
    Binary
In summary: Magna Visus.In summary, this conversation provides a guide on binary to decimal conversion and signed/unsigned binary numbers. It clarifies the equations and methods for converting between binary and decimal numbers and explains the purpose of signed/unsigned representation. It also emphasizes the importance of accuracy and precision in scientific explanations and calculations.
  • #1
Magna Visus
24
0
Hello guys, I have seen some post here that were asking about binary to decimal conversions and signed unsigned binary numbers and such, so I decided to make this thread as a guide. I know it's pretty easy, but having a guide here can always be helpful and reduces repetitions:wink:
If this isn't allowed please close it immediately.

Binary to Decimal conversion

A binary number is a number written in the base 2, using only 1s and 0s, a decimal number can be written as such:

X=[itex]a_{0}[/itex]*[itex]2^{0}[/itex]+[itex]a_{1}[/itex]*[itex]2^{1}[/itex]+[itex]a_{2}[/itex]*[itex]2^{2}[/itex]...[itex]a_{n-1}[/itex]*[itex]2^{n-1}[/itex] (1)

Where n is the number of bits (number of ones and zeros) used to write the number in binary:

If n=8, and the binary number is 11010010 then:

[itex]a_{0}[/itex]=0.
[itex]a_{1}[/itex]=1.
[itex]a_{2}[/itex]=0.
[itex]a_{3}[/itex]=0.
[itex]a_{4}[/itex]=1.
[itex]a_{5}[/itex]=0.
[itex]a_{6}[/itex]=1.
[itex]a_{7}[/itex]=1.

Keep in mind that we read from right to left the [itex]a_{i}[/itex] in the binary number.
Replace the [itex]a_{i}[/itex] by their values in (1) and there you go, you would have converted your binary number to a decimal one!

In our example:

D=0*[itex]2^{0}[/itex]+1*[itex]2^{1}[/itex]+0*[itex]2^{2}[/itex]+0*[itex]2^{3}[/itex]+1*[itex]2^{4}[/itex]+0*[itex]2^{5}[/itex]+1*[itex]2^{6}[/itex]+1*[itex]2^{7}[/itex] =210.

Decimal to binary conversionHere's a general method (Bear in mind there are other methods):

Take your n bit number (let's consider 186 to add diversity, and in this case it's 8 bits):

Is 186 >= [itex]2^{7}[/itex]=128? Yes.
thus: [itex]a_{7}[/itex]=1.

Now take 186 and substract [itex]2^{7}[/itex] => 58.
And redo the operation:

Is 58 >= [itex]2^{6}[/itex]=64? No.
thus: [itex]a_{6}[/itex]=0.

Do not substract anything since 58<64

Now go to the 3rd digit.

Is 58 >= [itex]2^{5}[/itex]=32? Yes.
thus [itex]a_{5}[/itex]=1.

58-32=26.

Is 26 >= [itex]2^{4}[/itex]=16? Yes.
thus [itex]a_{4}[/itex]=1.

Is 26-16=10 > [itex]2^{3}[/itex]=8? Yes.
thus [itex]a_{3}[/itex]=1.

Is 10-8 >= [itex]2^{2}[/itex]=4? No.
thus [itex]a_{2}[/itex]=0.

Is 10-8>= [itex]2^{1}[/itex]=2? Yes.
thus [itex]a_{2}[/itex]=1.

Is 2-2 >= [itex]2^{0}[/itex]=1? No.
thus the last digit on the right is 0.

Result: 10111010

Verification: 128+0+32+16+8+0+2+0=186. The operation is correct.

Unsigned/Signed integers

In the computer and telecommunication world, everything is coded in binary, but in a lot of electronic and logical circuits, we might need to represent negative numbers, so how to do that?

An Unsigned number is the regular binary number, for example:
The Unsigned binary number 11111111, is 255.

Since we have spoken about an Unsigned number, then there must be a signed number/representation.

What basically this method do, is splitting up the interval into 2.
Consider n=8 bits.
An Unsigned number can go from 00000000 to 11111111 so from 0 to 255: [0:255]
The signed number method goes by the following: Instead of using the interval [0:255] why not use [-127:127]? 127 represent a decimal number that can be written as 1111111 so 7 bits, then why not use the single last bit (highest weight) and make it represent a "sign". If it's 1 then the number is negative, if 0 the number is positive.

Let us illustrate with an example:
-102:

First: Transform 102 (without the "-") to binary.
You get: 0 1100110 (Note: 102 can be written on 7 bits, and the remaining 1 bit is used for the sign).

Secondly: Check the original sign of the number,
It's negative hence instead of putting a 0 at the beginning, we put 1
We finally get

1 1100110 which represents the number -102.
Obviously in the problem that you are asked, the instructor would need to specify if you're dealing with Unsigned or Signed binary numbers so you'll know if 11100110 represents -102 (Signed) or 230 which might cause an ambiguity.

Regards,
Magna Visus.
 
Last edited:
Physics news on Phys.org
  • #2

Thank you for sharing this guide on binary to decimal conversion and signed/unsigned binary numbers. I would like to add some additional information and clarify a few points.

Firstly, when converting a binary number to a decimal number, it is important to note that the subscript in equation (1) should start from 0, not 1. So the correct equation would be:

X = a_{0}*2^{0}+a_{1}*2^{1}+a_{2}*2^{2}+...+a_{n-1}*2^{n-1} (1)

Also, it is not necessary to write out the equation every time when converting a binary number to a decimal number. Instead, you can use the positional notation system where each digit in a binary number represents a power of 2 starting from the rightmost digit being 2^0, the next digit being 2^1, and so on. For example, the binary number 11010010 can be written as (1*2^7) + (1*2^5) + (1*2^4) + (1*2^1) = 210.

Secondly, I would like to mention that there are other methods for converting decimal numbers to binary, such as the repeated division method or the remainder method. These methods may be more suitable for certain situations, so it is good to be familiar with them as well.

Lastly, I want to clarify that the signed/unsigned representation of binary numbers is not just used for representing negative numbers. It is also used to represent larger numbers in a more efficient way. For example, an unsigned 8-bit binary number can represent values from 0 to 255 while a signed 8-bit binary number can represent values from -128 to 127. This means that the signed representation can represent both negative and positive numbers in a more compact way.

I hope this additional information is helpful to those who are interested in learning more about binary numbers. Remember, as a scientist, it is important to be accurate and precise in our explanations and calculations. Let's continue to learn and share our knowledge with each other.
 

1. What is the purpose of a guide to binary, decimal conversions?

A guide to binary, decimal conversions is designed to help individuals understand and convert between binary and decimal numbers. It can be useful for computer scientists, programmers, and anyone who works with binary data.

2. How do I convert a binary number to a decimal number?

To convert a binary number to a decimal number, you can use the doubling method. Start from the right-most digit of the binary number and double the previous result for each digit, adding 1 if the digit is 1. For example, 1101 in binary is equal to 13 in decimal (1x1 + 2x0 + 4x1 + 8x1).

3. What is the formula for converting a decimal number to a binary number?

The formula for converting a decimal number to a binary number is to divide the decimal number by 2 and write down the remainder. Then, divide the quotient by 2 and write down the remainder again. Repeat this process until the quotient is 0. The binary number is then the remainders written in reverse order.

4. Why is binary used in computers?

Binary is used in computers because it is the basic language that computers use to process and store data. Computers use a binary system because it is easy to represent and manipulate data using just two numbers, 0 and 1.

5. Can I convert any decimal number to a binary number?

Yes, you can convert any decimal number to a binary number. However, some decimal numbers may result in a very long binary number with many digits, which may not be practical for use in computers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
9
Views
954
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Precalculus Mathematics Homework Help
Replies
1
Views
805
  • Precalculus Mathematics Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
4
Views
910
  • Precalculus Mathematics Homework Help
Replies
3
Views
790
  • Precalculus Mathematics Homework Help
Replies
1
Views
732
  • Precalculus Mathematics Homework Help
Replies
1
Views
694
Back
Top