ghy
Alejandro Acuña
2025-03-12 26319e4c5bfbee722c15b8e7ccca9b6127bb1cb8
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package art.servers.fleetserver.radio.sepura;
 
public class BinaryStreamASCII 
{
    private String data = null;
    private int pointer = 0;
    
    public BinaryStreamASCII(String data)
    {
        this.data = hexStringToBinaryString(data);
    }
    
    public long readLong (int length) throws Exception
    {
        if ((pointer + length) > data.length()) throw new Exception();
        String value = data.substring(pointer, pointer + length);
        pointer = pointer + length;
        return Long.parseLong(value, 2);
    }
 
    
    public void skip (int length) throws Exception
    {
        if ((pointer + length) > data.length()) throw new Exception();
        pointer = pointer + length;
    }
    
    
    public void reset ()
    {
        pointer = 0;
    }
    
    
 
  private static String hexStringToBinaryString(String input) 
  {
      String result = "";
      
      for (int i=0; i<input.length(); i++)
      {
         String hex = input.substring(i, i+1);
         int decimal = Integer.valueOf(hex, 16);
         result = result + leadingZeros(Integer.toBinaryString(decimal), 4);
     }
      
      return result;
  }    
    
  
 
  
  private static String leadingZeros(String input, int length)
  {
      return (new String(new char[length - input.length()]).replace("\0", "0") + input);
  }
  
  
}