Converting Hexadecimal (base 16) to Octal (base 8)

  • Thread starter WaterRain
  • Start date
  • Tags
    hexadecimal
In summary, to convert a hexadecimal value to octal, first convert it to decimal, then to octal, using the regroup method of grouping 3 binary digits to represent octal digits for both the integral and fractional parts. Another method is to convert the hex value to binary, regrouping 4 binary digits to represent octal digits, and then converting back to octal. It is also possible to use the simple method of converting each hex digit to two octal digits, by adding a 0 in front if the hex digit is less than 8, and subtracting 8 and adding a 1 in front if the hex digit is greater than 8. However, this method only works for single hex digits and
  • #1
WaterRain
13
0

Homework Statement


Convert the hexadecimal (base 16) value FACE.BE into octal (base 8), correct
to 2 octal places.


Homework Equations


Nil


The Attempt at a Solution


First, I've converted the FACE.BE to decimals and I got 64206.742188

Next I change them to octal
64206(dec) = 175316(oct)

However, I'm unsure with the 0.742188
I continued my solution by treating it is 742188 and got 2651454

If that's the case, my answer is 175316.27(oct).
Is this answer correct?
Any quicker way to do it like Octal to Hexadecimal without the need to convert into Decimal first.
 
Physics news on Phys.org
  • #2
I realized I made a mistake.

0.742188 should give 0.574 instead.

1. Answer is 175316.57?
2. Any quicker way to convert from Hex to Oct?
 
  • #3
Yes, each hex digit is two octal digits.
Take the hex digit, if it is less than 8 it's already octal - just put an 0 in front.
If it's more than 8, subtract 8, and put a 1 in front of the result.

eg. F = 1 7 ( ie 1*8 + 7)
 
  • #4
It would be relatively easy if you convert hex into binary (1 hex digit gives 4 digits of binary) and then regrouping the resulting number 3 digits at a time to make octal digits, starting from the decimal point.
Your answer for the integral part is correct, but you can confirm it using the binary conversion.
The fractional part is represented by fractions, for example:
0.123= 1/10 + 2/100 + 3/1000 (in decimal)
So
0.BE = B/16 + E/256 (in hex)
(Yes, 0.BE (hex) gives 0.574 (octal))
and
0.257 = 2/8 + 5/64 + 7/512 (in Octal)

The procedure of grouping 3 binary digits to represent octal digits for the fractional part is the same as in the integral part, namely you must start the grouping from the decimal point towards the right, and pad remaining digits with zeroes if the number of non-zero digits to the right of the decimal (or rather octal) point is not divisible by 3.
 
  • #5
mgb_phys said:
Yes, each hex digit is two octal digits.
Take the hex digit, if it is less than 8 it's already octal - just put an 0 in front.
If it's more than 8, subtract 8, and put a 1 in front of the result.

eg. F = 1 7 ( ie 1*8 + 7)

Does this only work for a single Hex?
 
  • #6
mgb_phys said:
Yes, each hex digit is two octal digits.

A hex digit is actually 4/3 of an octal digit. So for example, FFF hex = 7777 octal.

The best way to see this is to convert hex to binary, then binary to octal.
 
  • #7
mathmate said:
It would be relatively easy if you convert hex into binary (1 hex digit gives 4 digits of binary) and then regrouping the resulting number 3 digits at a time to make octal digits, starting from the decimal point.
Your answer for the integral part is correct, but you can confirm it using the binary conversion.
The fractional part is represented by fractions, for example:
0.123= 1/10 + 2/100 + 3/1000 (in decimal)
So
0.BE = B/16 + E/256 (in hex)
(Yes, 0.BE (hex) gives 0.574 (octal))
and
0.257 = 2/8 + 5/64 + 7/512 (in Octal)

The procedure of grouping 3 binary digits to represent octal digits for the fractional part is the same as in the integral part, namely you must start the grouping from the decimal point towards the right, and pad remaining digits with zeroes if the number of non-zero digits to the right of the decimal (or rather octal) point is not divisible by 3.

I get it now - partially.

FACE = 1111 1010 1100 1110
regroup = 001 111 101 011 001 110
Oct = 175316

But for .BE, it is not possible to do likewise but to use the method you suggest
0.BE = B/16 + E/256

Is this right?
 
  • #8
DoctorBinary said:
A hex digit is actually 4/3 of an octal digit. So for example, FFF hex = 7777 octal.

The best way to see this is to convert hex to binary, then binary to octal.

I see. This means if converting a single hex I can use as mgb_phys suggested right?
example F(hex) = 17(oct).

mgb_phys said:
Take the hex digit, if it is less than 8 it's already octal - just put an 0 in front.
If it's more than 8, subtract 8, and put a 1 in front of the result.

Anything more than one hex will not work.
Like FFF(hex) = 7777(oct).
 
  • #9
WaterRain said:
I see. This means if converting a single hex I can use as mgb_phys suggested right?
example F(hex) = 17(oct).

Anything more than one hex will not work.
Like FFF(hex) = 7777(oct).

For one hex digit, and if it's to the left of the radix point -- yes, mgb_phys's method works. But why have two methods? The "write hex in binary and regroup to octal" method that mathmate outlines will work for any number of digits, and is easy to apply on both sides of the radix point (just remember to pad 0s away from the radix point).
 
  • #10
WaterRain said:
I get it now - partially.

FACE = 1111 1010 1100 1110
regroup = 001 111 101 011 001 110
Oct = 175316

But for .BE, it is not possible to do likewise but to use the method you suggest
0.BE = B/16 + E/256

Is this right?

Just to be clear, let's spell out the whole solution, using the regroup method for the entire number (you got the integer part -- I'm just adding the fractional part):

FACE.BE = 1111 1010 1100 1110.1011 1110
regroup = 001 111 101 011 001 110.101 111 100
Oct = 175316.574
 
  • #11
DoctorBinary said:
Just to be clear, let's spell out the whole solution, using the regroup method for the entire number (you got the integer part -- I'm just adding the fractional part):

FACE.BE = 1111 1010 1100 1110.1011 1110
regroup = 001 111 101 011 001 110.101 111 100
Oct = 175316.574

Thanks DoctorBinary. I fully understand where my mistake is now.

.BE = .1011 1110
regroup = .010 111 110
Oct = .276
That's why I thought we can't apply the same to the fractional part. But now I got it.

Thanks to mgb_phys and mathmate as well :)
 
  • #12
It's worth noting that the figures to the right of the decimal point are only used in maths HW questions.
Sorry for my confusion on the fractional part - in computers real numbers are stored as IEEE floating point format.
 
  • #13
WaterRain said:
Thanks DoctorBinary. I fully understand where my mistake is now.

.BE = .1011 1110
regroup = .010 111 110
Oct = .276
That's why I thought we can't apply the same to the fractional part. But now I got it.

Thanks to mgb_phys and mathmate as well :)

Hmm, seems like you've taken a step backwards. Why did you rewrite the fractional part? The way I had it was correct:

.BE = .1011 1110
regroup = .101 111 100
Oct = .574

To the right of the radix point you pad the 0s to the right, not left!
 
  • #14
I got it. I was showing what I did earlier which resulted in my mistake :)
 

Related to Converting Hexadecimal (base 16) to Octal (base 8)

1. What is the process for converting hexadecimal to octal?

The process for converting hexadecimal to octal involves breaking the hexadecimal number into groups of three digits, starting from the right. Each group can then be converted to its corresponding octal digit. If there is a remainder when dividing by three, leading zeros may need to be added to make groups of three digits.

2. How do I convert a hexadecimal number with letters to octal?

For hexadecimal numbers with letters (A-F), they can be converted to their decimal equivalent first before converting to octal. This can be done by multiplying the hexadecimal digit by its place value (16^0, 16^1, 16^2, etc.), and then adding the results together. The resulting decimal number can then be converted to octal.

3. Can a hexadecimal number be converted directly to octal without going through decimal?

Yes, a hexadecimal number can be converted directly to octal by grouping the digits into groups of three from the right and converting each group to its corresponding octal digit. However, this method may be more difficult for numbers with letters.

4. What is the difference between hexadecimal and octal?

Hexadecimal and octal are both number systems used to represent numbers in different bases. Hexadecimal uses 16 digits (0-9 and A-F) while octal uses 8 digits (0-7). Hexadecimal is commonly used in computing, while octal is less commonly used but can be useful for representing binary numbers in a more compact form.

5. Can I convert octal back to hexadecimal?

Yes, octal can be converted back to hexadecimal by first converting to decimal and then converting the decimal number to hexadecimal. Alternatively, you can convert the octal number to binary and then to hexadecimal, as both binary and hexadecimal are base 2 systems, making the conversion simpler.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
927
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
3
Views
980
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
10K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
Back
Top