Created
March 11, 2017 18:12
-
-
Save padcom/489ff8ba03a24f50f54cdd31c7e4974a to your computer and use it in GitHub Desktop.
Display all codes of type A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env groovy | |
| noru2bit = [ '0': '00', '1': '11', 'F': '01', 'X': '10' ] | |
| def getCodeWord(String group, String device, Boolean status) { | |
| char[] result = new char[12]; | |
| int idx = 0 | |
| for (int i = 0; i < 5; i++) { | |
| result[idx++] = (group[i] == '0') ? 'F' : '0' | |
| } | |
| for (int i = 0; i < 5; i++) { | |
| result[idx++] = (device[i] == '0') ? 'F' : '0' | |
| } | |
| result[idx++] = status ? '0' : 'F' | |
| result[idx++] = status ? 'F' : '0' | |
| return new String(result) | |
| } | |
| def getCodeWord(int group, int device, Boolean status) { | |
| if (group > 31) throw new Exception("Group must be between 0 and 31") | |
| if (device > 31) throw new Exception("Device must be between 0 and 31") | |
| return getCodeWord( | |
| Integer.toString(group, 2).padLeft(5, '0'), | |
| Integer.toString(device, 2).padLeft(5, '0'), | |
| status) | |
| } | |
| def convertNoruToBin(s) { | |
| def result = "" | |
| s.collect { noru2bit[it] }.join("") | |
| } | |
| for (int i = 0; i < 32; i++) { | |
| for (int j = 0; j < 32; j++) { | |
| code = getCodeWord(i, j, true) | |
| println "${i.toString().padLeft(2)}/${j.toString().padLeft(2)}/1 -> ${code} -> ${convertNoruToBin(code)} -> ${Integer.parseInt(convertNoruToBin(code), 2)}" | |
| code = getCodeWord(i, j, false) | |
| println "${i.toString().padLeft(2)}/${j.toString().padLeft(2)}/0 -> ${code} -> ${convertNoruToBin(code)} -> ${Integer.parseInt(convertNoruToBin(code), 2)}" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment