Converting Between Binary, Hex, Octal, and Decimal

  • Thread starter Lancelot59
  • Start date
  • Tags
    Binary
In summary, to convert between binary, octal, and hexadecimal, you just have to know the lengths of the strings of numbers and multiply each number by its base to the power of the place of that number in the string. For example, to convert from hex to decimal, you would just write:x = (16*6+4)*256^1 + (16*5)*256^0 = 100*256+80 = 25680
  • #1
Lancelot59
646
1
I'm taking a microcontrollers course and need to know how to convert between base 2, 8, 16, and 10. I understand how each base works, however I'm finding it hard to convert between them. What are some good methods to use when converting bases?
 
Physics news on Phys.org
  • #2
I find the easiest way (by hand) is to just make grids.

I.e.

32|16|8|4|2|1

or

1048576|65536|4096|256|16|1

And then fill them out, and add up the numbers.
 
  • #3
I know of that method, but I don't think it would be very effective for large numbers...is it?
 
  • #4
I suppose there are faster ways...

Read the number of elements and multiply each element by the base to the power of the place of that element (counting the right most element as place 0). Like, for if we have the number:

xyztu

In base b. Then there are 5 elements, so in decimal, it's just:

x*b^4+y*b^3+z*b^2+t*b^1+u*b^0

e.g. For Hex:
13ae3
1*16^4+3*16^3+11*16^2+15*16^1+3

I don't really know of any faster ways than this...I'll think about it and see if i can think up something haha.
 
  • #5
Converting between binary and octal or hexadecimal is pretty easy.

Binary to octal:

000 = 0
001 = 1
010 = 2
011 = 3
100 = 4
101 = 5
110 = 6
111 = 7

For example, octal 436 = binary 100 011 110.

Similarly, between binary and hexadecimal, you have

0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = A
1011 = B
1100 = C
1101 = D
1110 = E
1111 = F

Binary 1101 1110 1010 1101 = Hex DEAD

For converting between decimal and the other bases, all I can suggest is knowing your multiples and powers of 2, 8, and 16. Sometimes converting binary to hex and then to decimal requires less work than going straight from base 2 to base 10, and likewise in the reverse direction.
 
  • #6
Ok, so how about conversions to/from decimal?

Matterwave said:
I suppose there are faster ways...

Read the number of elements and multiply each element by the base to the power of the place of that element (counting the right most element as place 0). Like, for if we have the number:

xyztu

In base b. Then there are 5 elements, so in decimal, it's just:

x*b^4+y*b^3+z*b^2+t*b^1+u*b^0

e.g. For Hex:
13ae3
1*16^4+3*16^3+11*16^2+15*16^1+3

I don't really know of any faster ways than this...I'll think about it and see if i can think up something haha.

I don't really understand how that method works, care to enlighten me?
 
Last edited:
  • #7
It's the same method with the grids, just without the grids. XD

When you make a grid, it's just:

b^4|b^3|b^2|b^1|b^0 etc. (in binary then it's 16|8|4|2|1)

Filling out your numbers there. Without the grid, it's just 0th power, 1st power, 2nd power, etc of your base. All you really need to know is the length of the string of numbers.
 
  • #8
One trick is to use a higher base, like base 256. For instance, suppose you wanted to know what x=hex 6450 is in decimal. Instead of saying

x = 6*16^3+4*16^2+5*16+0*1 = 25680

which requires you to calculate what 16^3 is, you could write

x = (16*6+4)*256^1 + (16*5)*256^0 = 100*256+80 = 25680

This method saves you a bit of effort because you don't need to know or calculate as many powers of 16 and because converting between hex and decimal is easier for the values from 0 to 255, especially if you know your multiples of 16 up to 16x15.
 

1. What is binary?

Binary is a numbering system that uses only two digits, 0 and 1, to represent numbers. It is the basis of all digital computing and is often used to store and manipulate data in computer systems.

2. What is hexadecimal?

Hexadecimal is a numbering system that uses 16 digits, 0-9 and A-F, to represent numbers. It is commonly used in computer programming to represent binary numbers in a more compact and easily readable format.

3. How do you convert binary to decimal?

To convert binary to decimal, you can use the place value method. Start from the rightmost digit and multiply each digit by 2 raised to the power of its position. Then, add all the results together to get the decimal equivalent.

4. How do you convert decimal to binary?

To convert decimal to binary, you can use the division method. Divide the decimal number by 2 and note down the remainder. Then, continue dividing the quotient by 2 and noting down the remainders until the quotient becomes 0. The binary equivalent is the sequence of remainders in reverse order.

5. Can you explain the importance of being able to convert between binary, hexadecimal, and decimal?

Being able to convert between binary, hexadecimal, and decimal is important in computer science and engineering as it allows for efficient and accurate representation and manipulation of data. Binary is used in digital computing, while hexadecimal is used in programming and data storage. Decimal is used in everyday calculations and is the most familiar to most people. The ability to convert between these systems is essential for working with different types of data in various contexts.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
880
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
Replies
4
Views
926
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
859
  • Engineering and Comp Sci Homework Help
Replies
1
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Introductory Physics Homework Help
Replies
3
Views
190
Back
Top