Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to convert decimal number into hex number in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
            int dec = 11594;
            String hex = "";
            
            while (dec != 0) {
                int hex_val = dec % 16;
                char hex_digit = (hex_val <= 9 && hex_val >= 0) ? (char)(hex_val + '0') : 
                                                                  (char)(hex_val - 10 + 'A'); 
                hex = hex_digit + hex;
                dec = dec / 16;
            }
            System.out.println(hex);
    }
}
 

 
 
/*
run:
 
2D4A

*/

 



answered Jun 14, 2019 by avibootz
edited Jun 14, 2019 by avibootz

Related questions

1 answer 85 views
1 answer 189 views
1 answer 217 views
1 answer 200 views
1 answer 95 views
1 answer 101 views
...