  I am trying to convert a number to hexadecimal. How do I do this without using modulus, division, and multiplication. Also, I can't import anything and I can't use any functions like Integer.toHexadecimal().

Question

I am trying to convert a number to hexadecimal. How do I do this without using modulus, division, and multiplication. Also, I can't import anything and I can't use any functions like Integer.toHexadecimal().

Step 1

To convert a decimal number into hexadecimal form with out using any of modulus, division or multiplication operator you need to use shift operators.

Step 2

The following code can be used to convert the number in decimal form into hexadecimal form using right shift operator:

Step 3

In the above program the for loop in line 39 will execute 7 times for the int type storage of 4 bytes. During the first iteration i will take the value of 7 i.e. (2×4) –1 =7. Then in the line 40, the input number “num” will be right sh...

Want to see the full answer?

See Solution

Want to see this answer and more?

Our solutions are written by experts, many with advanced degrees, and available 24/7

See Solution
Tagged in

Computer Science 