Hey,
I want to write a programm which can convert decimal to hex but without the "toHexString".
I very new in programming/java so its kinda hard for me at this point.
Right now I have this (plz dont laugh :D)
My Idea with this loop was the following:
for example n=22, then the loop will
22/16 = 1 mod: 6 --> 6
1/16 = 0 mod: 1 --> 1
so the right hex number would be 16. Yea I know I need to make the number >9 change to A, B, C... I could solve this with switch, I think. Can someone help me how to get it done?
I want to write a programm which can convert decimal to hex but without the "toHexString".
I very new in programming/java so its kinda hard for me at this point.
Right now I have this (plz dont laugh :D)
PHP Code
<?php
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
int m;
while (n > 0){
m = n%16;
n = n/16;
System.out.println(n);
System.out.println(m);
}
My Idea with this loop was the following:
for example n=22, then the loop will
22/16 = 1 mod: 6 --> 6
1/16 = 0 mod: 1 --> 1
so the right hex number would be 16. Yea I know I need to make the number >9 change to A, B, C... I could solve this with switch, I think. Can someone help me how to get it done?

