Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Momchil.ZaSrqda;
- import java.util.Arrays;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.concurrent.atomic.AtomicInteger;
- public class Main {
- private static Map<String, Integer> map = new LinkedHashMap<>();
- static {
- map.put(".", 75);
- map.put("A", 193);
- map.put("B", 194);
- map.put("C", 195);
- map.put("D", 196);
- map.put("E", 197);
- map.put("F", 198);
- map.put("G", 199);
- map.put("H", 200);
- map.put("I", 201);
- map.put("J", 209);
- map.put("K", 210);
- map.put("L", 211);
- map.put("M", 212);
- map.put("N", 213);
- map.put("O", 214);
- map.put("P", 215);
- map.put("Q", 216);
- map.put("R", 217);
- map.put("S", 226);
- map.put("T", 227);
- map.put("U", 228);
- map.put("V", 229);
- map.put("W", 230);
- map.put("X", 231);
- map.put("Y", 232);
- map.put("Z", 233);
- map.put("a", 129);
- map.put("b", 130);
- map.put("c", 131);
- map.put("d", 132);
- map.put("e", 133);
- map.put("f", 134);
- map.put("g", 135);
- map.put("h", 136);
- map.put("i", 137);
- map.put("j", 145);
- map.put("k", 146);
- map.put("l", 147);
- map.put("m", 148);
- map.put("n", 149);
- map.put("o", 150);
- map.put("p", 151);
- map.put("q", 152);
- map.put("r", 152);
- map.put("s", 162);
- map.put("t", 163);
- map.put("u", 164);
- map.put("v", 165);
- map.put("w", 166);
- map.put("x", 167);
- map.put("y", 168);
- map.put("z", 169);
- map.put("#", 123);
- map.put("0", 240);
- map.put("1", 241);
- map.put("2", 242);
- map.put("3", 243);
- map.put("4", 244);
- map.put("5", 245);
- map.put("6", 246);
- map.put("7", 247);
- map.put("8", 248);
- map.put("9", 249);
- map.put("CR", 13);
- map.put("LF", 37);
- map.put(" ", 64);
- }
- public static void main(String[] args) {
- String names = "Borislav Radoslavov Nachev";
- String number = "#6";
- String date = "01.07.2003";
- String[][] asciiInfo = getAsciiValues(new String[]{names, number, date});
- pribtMatrix(asciiInfo);
- String[][] ebcdicInfo = getEbcidcValues(new String[]{names, number, date});
- pribtMatrix(ebcdicInfo);
- }
- //TODO add carrige new line feed
- public static void pribtMatrix(String[][] matrix) {
- for (int i = 0; i < matrix.length; i++) {
- for (int j = 0; j < matrix[i].length; j++) {
- System.out.println(matrix[i][j] + " ");
- }
- System.out.println();
- }
- }
- public static String[][] getEbcidcValues(String[] words) {
- String[][] matrix = new String[3][3];
- for (int i = 0; i < words.length; i++) {
- matrix[0][i] = formatArray(words[i], getBinaryEbcidValues(words[i]));
- matrix[1][i] = formatArray(words[i], getOctalEbcidValues(words[i]));
- matrix[2][i] = formatArray(words[i], getHexEbcidValues(words[i]));
- }
- return matrix;
- }
- public static String[] getBinaryEbcidValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toBinaryString(map.get(e))).toArray(String[]::new);
- }
- public static String[] getOctalEbcidValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toOctalString(map.get(e))).toArray(String[]::new);
- }
- public static String[] getHexEbcidValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toHexString(map.get(e))).toArray(String[]::new);
- }
- public static String[][] getAsciiValues(String[] words) {
- String[][] matrix = new String[3][3];
- for (int i = 0; i < words.length; i++) {
- matrix[0][i] = formatArray(words[i], getBinaryAsciiValues(words[i]));
- matrix[1][i] = formatArray(words[i], getOctalAsciiValues(words[i]));
- matrix[2][i] = formatArray(words[i], getHexAsciiValues(words[i]));
- }
- return matrix;
- }
- private static String formatArray(String names, String[] array) {
- final String[] toReturn = {""};
- AtomicInteger index = new AtomicInteger();
- Arrays.stream(array).forEach(e -> toReturn[0] += String.format("%c -> %s ", names.charAt(index.getAndIncrement()), e));
- return toReturn[0];
- }
- public static String[] getBinaryAsciiValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toBinaryString(e.charAt(0))).toArray(String[]::new);
- }
- public static String[] getOctalAsciiValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toOctalString(e.charAt(0))).toArray(String[]::new);
- }
- public static String[] getHexAsciiValues(String names) {
- return Arrays.stream(names.split("")).map(e -> Integer.toHexString(e.charAt(0))).toArray(String[]::new);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement