-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecToHexadecimal.java
More file actions
42 lines (32 loc) · 1 KB
/
DecToHexadecimal.java
File metadata and controls
42 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<<<<<<< HEAD
//405. Convert a Number to Hexadecimal
class Solution {
public String toHex(int num) {
if(num == 0) return "0";
char[] value = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
StringBuilder hex = new StringBuilder();
long n = num & 0xFFFFFFFFL;
while(n > 0){
int rem = (int)(n % 16);
hex.append(value[rem]);
n /= 16;
}
return hex.reverse().toString();
}
=======
//405. Convert a Number to Hexadecimal
class Solution {
public String toHex(int num) {
if(num == 0) return "0";
char[] value = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
StringBuilder hex = new StringBuilder();
long n = num & 0xFFFFFFFFL;
while(n > 0){
int rem = (int)(n % 16);
hex.append(value[rem]);
n /= 16;
}
return hex.reverse().toString();
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}