import
java.util.*;
class
Main {
public
static
String
convertToDec(String value,
int
base,
Map<Character, Integer> hexatoDec)
{
int
sum =
0
;
int
pow =
0
;
String tempData = value;
for
(
int
i = tempData.length() -
1
; i >=
0
; i--) {
int
val = tempData.charAt(i) -
'0'
;
if
(base ==
16
&& hexatoDec.containsKey(
tempData.charAt(i))) {
val = hexatoDec.get(tempData.charAt(i));
}
sum += (val) * (Math.pow(base, pow++));
}
return
String.valueOf(sum);
}
public
static
String
convertToDuoDecimal(String value,
int
base,
Map<Integer, Character> dectoHex,
Map<Character, Integer> hextoDec)
{
String val = value;
int
newBase = base;
if
(newBase !=
10
) {
val = convertToDec(value, base, hextoDec);
newBase =
10
;
}
int
temp = Integer.parseInt(val);
int
rem;
String duoDecimal =
""
;
char
duoDecimalChars[]
= {
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
};
while
(temp >
0
) {
rem = temp %
12
;
duoDecimal = duoDecimalChars[rem] + duoDecimal;
temp = temp /
12
;
}
return
duoDecimal;
}
public
static
void
main(String[] args)
{
String val;
val =
"3A4C2"
;
Map<Character, Integer> hexatoDec =
new
HashMap<>();
Map<Integer, Character> dectoHex =
new
HashMap<>();
for
(
int
i =
0
; i <
6
; i++) {
dectoHex.put(
10
+ i, (
char
)(
'A'
+ i));
hexatoDec.put((
char
)(
'A'
+ i),
10
+ i);
}
System.out.println(
"Duodecimal : "
+ convertToDuoDecimal(val,
16
, dectoHex,
hexatoDec));
}
}