1 | static byte[] hexToBytes(S s) { |
2 | if (odd(l(s))) fail("Hex string has odd length: " + quote(shorten(10, s))); |
3 | int n = l(s) / 2; |
4 | byte[] bytes = new byte[n]; |
5 | for (int i = 0; i < n; i++) { |
6 | int a = parseHexChar(s.charAt(i*2)); |
7 | int b = parseHexChar(s.charAt(i*2+1)); |
8 | if (a < 0 || b < 0) |
9 | fail("Bad hex byte: " + quote(substring(s, i*2, i*2+2)) + " at " + i*2 + "/" + l(s)); |
10 | bytes[i] = (byte) ((a << 4) | b); |
11 | } |
12 | ret bytes; |
13 | } |
Began life as a copy of #2000460
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, elmgxqgtpvxh, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, ofpaelxlmzfo, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004113 |
Snippet name: | hexToBytes |
Eternal ID of this version: | #1004113/7 |
Text MD5: | f7b8bd3fee731edb2ac3f889c5f7ad97 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-05-11 02:04:59 |
Source code size: | 460 bytes / 13 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 724 / 739 |
Version history: | 6 change(s) |
Referenced in: | [show references] |