Converting Between Binary, Hex, Octal, and Decimal

  • Thread starter Thread starter Lancelot59
  • Start date Start date
  • Tags Tags
    Binary
Click For Summary

Discussion Overview

The discussion revolves around methods for converting between binary, octal, hexadecimal, and decimal number systems. Participants explore various techniques and share their experiences, focusing on both theoretical understanding and practical applications relevant to microcontrollers.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant mentions using grids to facilitate conversions between bases, suggesting it is an effective method for visualizing the process.
  • Another participant questions the effectiveness of the grid method for large numbers, implying a need for faster techniques.
  • A method is proposed that involves multiplying each digit by the base raised to the power of its position, illustrated with an example using hexadecimal.
  • Participants provide specific conversion examples between binary and octal, as well as binary and hexadecimal, detailing the direct mappings of bits to values.
  • One participant notes that converting binary to hexadecimal and then to decimal can sometimes be less labor-intensive than converting directly from binary to decimal.
  • A suggestion is made to use a higher base, such as base 256, to simplify certain conversions, particularly when dealing with hexadecimal values.

Areas of Agreement / Disagreement

Participants express varying opinions on the effectiveness of different conversion methods, and no consensus is reached regarding the best approach for all scenarios. Multiple competing views on techniques remain present throughout the discussion.

Contextual Notes

Some methods discussed depend on familiarity with powers of bases and may not be universally applicable to all number sizes or contexts. The effectiveness of certain techniques may vary based on individual preferences and specific conversion tasks.

Lancelot59
Messages
640
Reaction score
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
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.
 
I know of that method, but I don't think it would be very effective for large numbers...is it?
 
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.
 
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.
 
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:
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.
 
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 10 ·
Replies
10
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
11K
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K