-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDecimal.java
More file actions
31 lines (28 loc) · 847 Bytes
/
Copy pathgetDecimal.java
File metadata and controls
31 lines (28 loc) · 847 Bytes
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
public class Hexadecimal {
public static int getDecimal(String hexValue){
//Convert hexadecimal to binary
int number = 0;
int[] digit = new int[20];
String values = "0123456789ABCDEF";
hexValue = hexValue.toUpperCase();
int val = 0;
for (int i = 0; i < hexValue.length(); i++)
{
char c = hexValue.charAt(i);
int d = values.indexOf(c);
val = 16*val + d;
}
System.out.println("Decimal value: " + val);
//Convert decimal value to an array
number = val;
for (int i = 0; i < 10; i++)
{
digit[i] = number % 10;
number = number / 10;
}
return digit[4];
}
public static void main(String args[]){
System.out.println(getDecimal("B8AB"));
}
}