Hi,
I need to write a Java program that takes a user input (integer), converts that to hexadecimal, flipps the value and outputs the result.
Flipping goes like this:
00037B54 -> 547B0300
(Last byte comes first, pre-last byte comes second, second byte comes second and first byte comes last).
I´m still missing the part where it flipps the value. The HEX output should always format to have 8 digits -> 00000063 (when 99 is entered) to make flipping easier.
I would use hexString.charAt(_); to talk to each position in the HEX number. It should store the result to a new array because otherwise it would overwrite the value from where it reads from.
Thanks for any tips.
I need to write a Java program that takes a user input (integer), converts that to hexadecimal, flipps the value and outputs the result.
Flipping goes like this:
00037B54 -> 547B0300
(Last byte comes first, pre-last byte comes second, second byte comes second and first byte comes last).
Java:
import javax.swing.JOptionPane;
public class ValueFlipping
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog("Please enter a number with up to 9 digits:");
try
{
int number = Integer.parseInt(input);
String hexString = Integer.toHexString(number);
// TODO 8 digited output & flipping
JOptionPane.showMessageDialog(null, "Result: "+hexString);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Invalid input!");
}
}
I would use hexString.charAt(_); to talk to each position in the HEX number. It should store the result to a new array because otherwise it would overwrite the value from where it reads from.
Thanks for any tips.
Zuletzt bearbeitet: