Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1033368 // hexToInts

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4670L/26K).

1  
static int[] hexToInts(S s) {
2  
  if (odd(l(s))) fail("Hex string has odd length: " + quote(shorten(10, s)));
3  
  int n = l(s) / 8;
4  
  int[] ints = new[n];
5  
  for i to n: {
6  
    int value = 0;
7  
    for j to 4: {
8  
      int idx = i*8+j*2;
9  
      int a = parseHexChar(s.charAt(idx));
10  
      int b = parseHexChar(s.charAt(idx+1));
11  
      if (a < 0 || b < 0)
12  
        fail("Bad hex byte: " + quote(substring(s, idx, idx+2)) + " at " + idx + "/" + l(s));
13  
      value |= ((a << 4) | b) << (j*8);
14  
    }
15  
    ints[i] = value;
16  
  }
17  
  ret ints;
18  
}

Author comment

Began life as a copy of #1004113

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033368
Snippet name: hexToInts
Eternal ID of this version: #1033368/3
Text MD5: 93e1e0806cf4c7461581c5c13cfe145d
Transpilation MD5: f3515c28b07ee2de1e047edd75b182fb
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-26 18:03:44
Source code size: 538 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 153 / 244
Version history: 2 change(s)
Referenced in: [show references]