online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
import java.util.*; public class Main { public class MyClass { // Public static variable public static String myNumber; public MyClass(String num) { myNumber = num; } } private static final int ERROR_CORRECTION_LENGTH = 15; // Error correction codewords for level L (15 codewords) public static void main(String[] args) { Scanner userInput = new Scanner(System.in); System.out.print("Please input text:"); String input = userInput.nextLine(); // Input string if (input.length()>151){ System.out.println("Text must be under 152 characters."); return; } String encodedData = encodeToBinary(input); // Step 1: Encoded data //System.out.println("Encoded Data: "); //System.out.println(formatBinaryWithSpaces(encodedData)); // Step 2: Generate error correction codewords int[] data = convertBinaryToIntArray(encodedData); // Convert the binary string to an integer array int[] errorCorrection = ReedSolomon.reedSolomonEncode(data, ERROR_CORRECTION_LENGTH); // Step 3: Combine the data and error correction codewords String combinedBinaryData = combineDataAndErrorCorrection(encodedData, errorCorrection); // System.out.println("\nCombined Data with Error Correction: "); //System.out.println(combinedBinaryData); MyClass.myNumber = combinedBinaryData; System.out.println(); PrintQRCode(); } public static void PrintQRCode(){ // Initialize the matrix with values int[][] matrix = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 0, 1, 1, 1, 0, 1, 0}, {0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 0, 1, 1, 1, 0, 1, 0}, {0, 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 3, 3, 3, 3, 0}, {0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; // Automatically detect the size of the matrix int rows = matrix.length; int cols = matrix[0].length; placeBit(matrix, 29, 29, 0); placeBit(matrix, 28, 29, 1); placeBit(matrix, 29, 28, 2); placeBit(matrix, 28, 28, 3); placeBit(matrix, 29, 27, 4); placeBit(matrix, 28, 27, 5); placeBit(matrix, 29, 26, 6); placeBit(matrix, 28, 26, 7); placeBit(matrix, 29, 25, 8); placeBit(matrix, 28, 25, 9); placeBit(matrix, 29, 24, 10); placeBit(matrix, 28, 24, 11); placeBit(matrix, 29, 23, 12); placeBit(matrix, 28, 23, 13); placeBit(matrix, 29, 22, 14); placeBit(matrix, 28, 22, 15); placeBit(matrix, 29, 21, 16); placeBit(matrix, 28, 21, 17); placeBit(matrix, 29, 20, 18); placeBit(matrix, 28, 20, 19); placeBit(matrix, 29, 19, 20); placeBit(matrix, 28, 19, 21); placeBit(matrix, 29, 18, 22); placeBit(matrix, 28, 18, 23); placeBit(matrix, 29, 17, 24); placeBit(matrix, 28, 17, 25); placeBit(matrix, 29, 16, 26); placeBit(matrix, 28, 16, 27); placeBit(matrix, 29, 15, 28); placeBit(matrix, 28, 15, 29); placeBit(matrix, 29, 14, 30); placeBit(matrix, 28, 14, 31); placeBit(matrix, 29, 13, 32); placeBit(matrix, 28, 13, 33); placeBit(matrix, 29, 12, 34); placeBit(matrix, 28, 12, 35); placeBit(matrix, 29, 11, 36); placeBit(matrix, 28, 11, 37); placeBit(matrix, 29, 10, 38); placeBit(matrix, 28, 10, 39); placeBit(matrix, 27, 10, 40); placeBit(matrix, 26, 10, 41); placeBit(matrix, 27, 11, 42); placeBit(matrix, 26, 11, 43); placeBit(matrix, 27, 12, 44); placeBit(matrix, 26, 12, 45); placeBit(matrix, 27, 13, 46); placeBit(matrix, 26, 13, 47); placeBit(matrix, 27, 14, 48); placeBit(matrix, 26, 14, 49); placeBit(matrix, 27, 15, 50); placeBit(matrix, 26, 15, 51); placeBit(matrix, 27, 16, 52); placeBit(matrix, 26, 16, 53); placeBit(matrix, 27, 17, 54); placeBit(matrix, 26, 17, 55); placeBit(matrix, 27, 18, 56); placeBit(matrix, 26, 18, 57); placeBit(matrix, 27, 19, 58); placeBit(matrix, 26, 19, 59); placeBit(matrix, 27, 20, 60); placeBit(matrix, 26, 20, 61); placeBit(matrix, 27, 21, 62); placeBit(matrix, 26, 21, 63); placeBit(matrix, 27, 22, 64); placeBit(matrix, 26, 22, 65); placeBit(matrix, 27, 23, 66); placeBit(matrix, 26, 23, 67); placeBit(matrix, 27, 24, 68); placeBit(matrix, 26, 24, 69); placeBit(matrix, 27, 25, 70); placeBit(matrix, 26, 25, 71); placeBit(matrix, 27, 26, 72); placeBit(matrix, 26, 26, 73); placeBit(matrix, 27, 27, 74); placeBit(matrix, 26, 27, 75); placeBit(matrix, 27, 28, 76); placeBit(matrix, 26, 28, 77); placeBit(matrix, 27, 29, 78); placeBit(matrix, 26, 29, 79); placeBit(matrix, 25, 29, 80); placeBit(matrix, 24, 29, 81); placeBit(matrix, 25, 28, 82); placeBit(matrix, 24, 28, 83); placeBit(matrix, 25, 27, 84); placeBit(matrix, 24, 27, 85); placeBit(matrix, 25, 26, 86); placeBit(matrix, 24, 26, 87); placeBit(matrix, 25, 20, 88); placeBit(matrix, 24, 20, 89); placeBit(matrix, 25, 19, 90); placeBit(matrix, 24, 19, 91); placeBit(matrix, 25, 18, 92); placeBit(matrix, 24, 18, 93); placeBit(matrix, 25, 17, 94); placeBit(matrix, 24, 17, 95); placeBit(matrix, 25, 16, 96); placeBit(matrix, 24, 16, 97); placeBit(matrix, 25, 15, 98); placeBit(matrix, 24, 15, 99); placeBit(matrix, 25, 14, 100); placeBit(matrix, 24, 14, 101); placeBit(matrix, 25, 13, 102); placeBit(matrix, 24, 13, 103); placeBit(matrix, 25, 12, 104); placeBit(matrix, 24, 12, 105); placeBit(matrix, 25, 11, 106); placeBit(matrix, 24, 11, 107); placeBit(matrix, 25, 10, 108); placeBit(matrix, 24, 10, 109); placeBit(matrix, 23, 10, 110); placeBit(matrix, 22, 10, 111); placeBit(matrix, 23, 11, 112); placeBit(matrix, 22, 11, 113); placeBit(matrix, 23, 12, 114); placeBit(matrix, 22, 12, 115); placeBit(matrix, 23, 13, 116); placeBit(matrix, 22, 13, 117); placeBit(matrix, 23, 14, 118); placeBit(matrix, 22, 14, 119); placeBit(matrix, 23, 15, 120); placeBit(matrix, 22, 15, 121); placeBit(matrix, 23, 16, 122); placeBit(matrix, 22, 16, 123); placeBit(matrix, 23, 17, 124); placeBit(matrix, 22, 17, 125); placeBit(matrix, 23, 18, 126); placeBit(matrix, 22, 18, 127); placeBit(matrix, 23, 19, 128); placeBit(matrix, 22, 19, 129); placeBit(matrix, 23, 20, 130); placeBit(matrix, 22, 20, 131); placeBit(matrix, 23, 26, 132); placeBit(matrix, 22, 26, 133); placeBit(matrix, 23, 27, 134); placeBit(matrix, 22, 27, 135); placeBit(matrix, 23, 28, 136); placeBit(matrix, 22, 28, 137); placeBit(matrix, 23, 29, 138); placeBit(matrix, 22, 29, 139); placeBit(matrix, 21, 29, 140); placeBit(matrix, 20, 29, 141); placeBit(matrix, 21, 28, 142); placeBit(matrix, 20, 28, 143); placeBit(matrix, 21, 27, 144); placeBit(matrix, 20, 27, 145); placeBit(matrix, 21, 26, 146); placeBit(matrix, 20, 26, 147); placeBit(matrix, 20, 25, 148); placeBit(matrix, 20, 24, 149); placeBit(matrix, 20, 23, 150); placeBit(matrix, 20, 22, 151); placeBit(matrix, 20, 21, 152); placeBit(matrix, 21, 20, 153); placeBit(matrix, 20, 20, 154); placeBit(matrix, 21, 19, 155); placeBit(matrix, 20, 19, 156); placeBit(matrix, 21, 18, 157); placeBit(matrix, 20, 18, 158); placeBit(matrix, 21, 17, 159); placeBit(matrix, 20, 17, 160); placeBit(matrix, 21, 16, 161); placeBit(matrix, 20, 16, 162); placeBit(matrix, 21, 15, 163); placeBit(matrix, 20, 15, 164); placeBit(matrix, 21, 14, 165); placeBit(matrix, 20, 14, 166); placeBit(matrix, 21, 13, 167); placeBit(matrix, 20, 13, 168); placeBit(matrix, 21, 12, 169); placeBit(matrix, 20, 12, 170); placeBit(matrix, 21, 11, 171); placeBit(matrix, 20, 11, 172); placeBit(matrix, 21, 10, 173); placeBit(matrix, 20, 10, 174); placeBit(matrix, 21, 9, 175); placeBit(matrix, 20, 9, 176); placeBit(matrix, 21, 8, 177); placeBit(matrix, 20, 8, 178); placeBit(matrix, 21, 6, 179); placeBit(matrix, 20, 6, 180); placeBit(matrix, 21, 5, 181); placeBit(matrix, 20, 5, 182); placeBit(matrix, 21, 4, 183); placeBit(matrix, 20, 4, 184); placeBit(matrix, 21, 3, 185); placeBit(matrix, 20, 3, 186); placeBit(matrix, 21, 2, 187); placeBit(matrix, 20, 2, 188); placeBit(matrix, 21, 1, 189); placeBit(matrix, 20, 1, 190); placeBit(matrix, 19, 1, 191); placeBit(matrix, 18, 1, 192); placeBit(matrix, 19, 2, 193); placeBit(matrix, 18, 2, 194); placeBit(matrix, 19, 3, 195); placeBit(matrix, 18, 3, 196); placeBit(matrix, 19, 4, 197); placeBit(matrix, 18, 4, 198); placeBit(matrix, 19, 5, 199); placeBit(matrix, 18, 5, 200); placeBit(matrix, 19, 6, 201); placeBit(matrix, 18, 6, 202); placeBit(matrix, 19, 8, 203); placeBit(matrix, 18, 8, 204); placeBit(matrix, 19, 9, 205); placeBit(matrix, 18, 9, 206); placeBit(matrix, 19, 10, 207); placeBit(matrix, 18, 10, 208); placeBit(matrix, 19, 11, 209); placeBit(matrix, 18, 11, 210); placeBit(matrix, 19, 12, 211); placeBit(matrix, 18, 12, 212); placeBit(matrix, 19, 13, 213); placeBit(matrix, 18, 13, 214); placeBit(matrix, 19, 14, 215); placeBit(matrix, 18, 14, 216); placeBit(matrix, 19, 15, 217); placeBit(matrix, 18, 15, 218); placeBit(matrix, 19, 16, 219); placeBit(matrix, 18, 16, 220); placeBit(matrix, 19, 17, 221); placeBit(matrix, 18, 17, 222); placeBit(matrix, 19, 18, 223); placeBit(matrix, 18, 18, 224); placeBit(matrix, 19, 19, 225); placeBit(matrix, 18, 19, 226); placeBit(matrix, 19, 20, 227); placeBit(matrix, 18, 20, 228); placeBit(matrix, 19, 21, 229); placeBit(matrix, 18, 21, 230); placeBit(matrix, 19, 22, 231); placeBit(matrix, 18, 22, 232); placeBit(matrix, 19, 23, 233); placeBit(matrix, 18, 23, 234); placeBit(matrix, 19, 24, 235); placeBit(matrix, 18, 24, 236); placeBit(matrix, 19, 25, 237); placeBit(matrix, 18, 25, 238); placeBit(matrix, 19, 26, 239); placeBit(matrix, 18, 26, 240); placeBit(matrix, 19, 27, 241); placeBit(matrix, 18, 27, 242); placeBit(matrix, 19, 28, 243); placeBit(matrix, 18, 28, 244); placeBit(matrix, 19, 29, 245); placeBit(matrix, 18, 29, 246); placeBit(matrix, 17, 29, 247); placeBit(matrix, 16, 29, 248); placeBit(matrix, 17, 28, 249); placeBit(matrix, 16, 28, 250); placeBit(matrix, 17, 27, 251); placeBit(matrix, 16, 27, 252); placeBit(matrix, 17, 26, 253); placeBit(matrix, 16, 26, 254); placeBit(matrix, 17, 25, 255); placeBit(matrix, 16, 25, 256); placeBit(matrix, 17, 24, 257); placeBit(matrix, 16, 24, 258); placeBit(matrix, 17, 23, 259); placeBit(matrix, 16, 23, 260); placeBit(matrix, 17, 22, 261); placeBit(matrix, 16, 22, 262); placeBit(matrix, 17, 21, 263); placeBit(matrix, 16, 21, 264); placeBit(matrix, 17, 20, 265); placeBit(matrix, 16, 20, 266); placeBit(matrix, 17, 19, 267); placeBit(matrix, 16, 19, 268); placeBit(matrix, 17, 18, 269); placeBit(matrix, 16, 18, 270); placeBit(matrix, 17, 17, 271); placeBit(matrix, 16, 17, 272); placeBit(matrix, 17, 16, 273); placeBit(matrix, 16, 16, 274); placeBit(matrix, 17, 15, 275); placeBit(matrix, 16, 15, 276); placeBit(matrix, 17, 14, 277); placeBit(matrix, 16, 14, 278); placeBit(matrix, 17, 13, 279); placeBit(matrix, 16, 13, 280); placeBit(matrix, 17, 12, 281); placeBit(matrix, 16, 12, 282); placeBit(matrix, 17, 11, 283); placeBit(matrix, 16, 11, 284); placeBit(matrix, 17, 10, 285); placeBit(matrix, 16, 10, 286); placeBit(matrix, 17, 9, 287); placeBit(matrix, 16, 9, 288); placeBit(matrix, 17, 8, 289); placeBit(matrix, 16, 8, 290); placeBit(matrix, 17, 6, 291); placeBit(matrix, 16, 6, 292); placeBit(matrix, 17, 5, 293); placeBit(matrix, 16, 5, 294); placeBit(matrix, 17, 4, 295); placeBit(matrix, 16, 4, 296); placeBit(matrix, 17, 3, 297); placeBit(matrix, 16, 3, 298); placeBit(matrix, 17, 2, 299); placeBit(matrix, 16, 2, 300); placeBit(matrix, 17, 1, 301); placeBit(matrix, 16, 1, 302); placeBit(matrix, 15, 1, 303); placeBit(matrix, 14, 1, 304); placeBit(matrix, 15, 2, 305); placeBit(matrix, 14, 2, 306); placeBit(matrix, 15, 3, 307); placeBit(matrix, 14, 3, 308); placeBit(matrix, 15, 4, 309); placeBit(matrix, 14, 4, 310); placeBit(matrix, 15, 5, 311); placeBit(matrix, 14, 5, 312); placeBit(matrix, 15, 6, 313); placeBit(matrix, 14, 6, 314); placeBit(matrix, 15, 8, 315); placeBit(matrix, 14, 8, 316); placeBit(matrix, 15, 9, 317); placeBit(matrix, 14, 9, 318); placeBit(matrix, 15, 10, 319); placeBit(matrix, 14, 10, 320); placeBit(matrix, 15, 11, 321); placeBit(matrix, 14, 11, 322); placeBit(matrix, 15, 12, 323); placeBit(matrix, 14, 12, 324); placeBit(matrix, 15, 13, 325); placeBit(matrix, 14, 13, 326); placeBit(matrix, 15, 14, 327); placeBit(matrix, 14, 14, 328); placeBit(matrix, 15, 15, 329); placeBit(matrix, 14, 15, 330); placeBit(matrix, 15, 16, 331); placeBit(matrix, 14, 16, 332); placeBit(matrix, 15, 17, 333); placeBit(matrix, 14, 17, 334); placeBit(matrix, 15, 18, 335); placeBit(matrix, 14, 18, 336); placeBit(matrix, 15, 19, 337); placeBit(matrix, 14, 19, 338); placeBit(matrix, 15, 20, 339); placeBit(matrix, 14, 20, 340); placeBit(matrix, 15, 21, 341); placeBit(matrix, 14, 21, 342); placeBit(matrix, 15, 22, 343); placeBit(matrix, 14, 22, 344); placeBit(matrix, 15, 23, 345); placeBit(matrix, 14, 23, 346); placeBit(matrix, 15, 24, 347); placeBit(matrix, 14, 24, 348); placeBit(matrix, 15, 25, 349); placeBit(matrix, 14, 25, 350); placeBit(matrix, 15, 26, 351); placeBit(matrix, 14, 26, 352); placeBit(matrix, 15, 27, 353); placeBit(matrix, 14, 27, 354); placeBit(matrix, 15, 28, 355); placeBit(matrix, 14, 28, 356); placeBit(matrix, 15, 29, 357); placeBit(matrix, 14, 29, 358); placeBit(matrix, 13, 29, 359); placeBit(matrix, 12, 29, 360); placeBit(matrix, 13, 28, 361); placeBit(matrix, 12, 28, 362); placeBit(matrix, 13, 27, 363); placeBit(matrix, 12, 27, 364); placeBit(matrix, 13, 26, 365); placeBit(matrix, 12, 26, 366); placeBit(matrix, 13, 25, 367); placeBit(matrix, 12, 25, 368); placeBit(matrix, 13, 24, 369); placeBit(matrix, 12, 24, 370); placeBit(matrix, 13, 23, 371); placeBit(matrix, 12, 23, 372); placeBit(matrix, 13, 22, 373); placeBit(matrix, 12, 22, 374); placeBit(matrix, 13, 21, 375); placeBit(matrix, 12, 21, 376); placeBit(matrix, 13, 20, 377); placeBit(matrix, 12, 20, 378); placeBit(matrix, 13, 19, 379); placeBit(matrix, 12, 19, 380); placeBit(matrix, 13, 18, 381); placeBit(matrix, 12, 18, 382); placeBit(matrix, 13, 17, 383); placeBit(matrix, 12, 17, 384); placeBit(matrix, 13, 16, 385); placeBit(matrix, 12, 16, 386); placeBit(matrix, 13, 15, 387); placeBit(matrix, 12, 15, 388); placeBit(matrix, 13, 14, 389); placeBit(matrix, 12, 14, 390); placeBit(matrix, 13, 13, 391); placeBit(matrix, 12, 13, 392); placeBit(matrix, 13, 12, 393); placeBit(matrix, 12, 12, 394); placeBit(matrix, 13, 11, 395); placeBit(matrix, 12, 11, 396); placeBit(matrix, 13, 10, 397); placeBit(matrix, 12, 10, 398); placeBit(matrix, 13, 9, 399); placeBit(matrix, 12, 9, 400); placeBit(matrix, 13, 8, 401); placeBit(matrix, 12, 8, 402); placeBit(matrix, 13, 6, 403); placeBit(matrix, 12, 6, 404); placeBit(matrix, 13, 5, 405); placeBit(matrix, 12, 5, 406); placeBit(matrix, 13, 4, 407); placeBit(matrix, 12, 4, 408); placeBit(matrix, 13, 3, 409); placeBit(matrix, 12, 3, 410); placeBit(matrix, 13, 2, 411); placeBit(matrix, 12, 2, 412); placeBit(matrix, 13, 1, 413); placeBit(matrix, 12, 1, 414); placeBit(matrix, 11, 1, 415); placeBit(matrix, 10, 1, 416); placeBit(matrix, 11, 2, 417); placeBit(matrix, 10, 2, 418); placeBit(matrix, 11, 3, 419); placeBit(matrix, 10, 3, 420); placeBit(matrix, 11, 4, 421); placeBit(matrix, 10, 4, 422); placeBit(matrix, 11, 5, 423); placeBit(matrix, 10, 5, 424); placeBit(matrix, 11, 6, 425); placeBit(matrix, 10, 6, 426); placeBit(matrix, 11, 8, 427); placeBit(matrix, 10, 8, 428); placeBit(matrix, 11, 9, 429); placeBit(matrix, 10, 9, 430); placeBit(matrix, 11, 10, 431); placeBit(matrix, 10, 10, 432); placeBit(matrix, 11, 11, 433); placeBit(matrix, 10, 11, 434); placeBit(matrix, 11, 12, 435); placeBit(matrix, 10, 12, 436); placeBit(matrix, 11, 13, 437); placeBit(matrix, 10, 13, 438); placeBit(matrix, 11, 14, 439); placeBit(matrix, 10, 14, 440); placeBit(matrix, 11, 15, 441); placeBit(matrix, 10, 15, 442); placeBit(matrix, 11, 16, 443); placeBit(matrix, 10, 16, 444); placeBit(matrix, 11, 17, 445); placeBit(matrix, 10, 17, 446); placeBit(matrix, 11, 18, 447); placeBit(matrix, 10, 18, 448); placeBit(matrix, 11, 19, 449); placeBit(matrix, 10, 19, 450); placeBit(matrix, 11, 20, 451); placeBit(matrix, 10, 20, 452); placeBit(matrix, 11, 21, 453); placeBit(matrix, 10, 21, 454); placeBit(matrix, 11, 22, 455); placeBit(matrix, 10, 22, 456); placeBit(matrix, 11, 23, 457); placeBit(matrix, 10, 23, 458); placeBit(matrix, 11, 24, 459); placeBit(matrix, 10, 24, 460); placeBit(matrix, 11, 25, 461); placeBit(matrix, 10, 25, 462); placeBit(matrix, 11, 26, 463); placeBit(matrix, 10, 26, 464); placeBit(matrix, 11, 27, 465); placeBit(matrix, 10, 27, 466); placeBit(matrix, 11, 28, 467); placeBit(matrix, 10, 28, 468); placeBit(matrix, 11, 29, 469); placeBit(matrix, 10, 29, 470); placeBit(matrix, 9, 21, 471); placeBit(matrix, 8, 21, 472); placeBit(matrix, 9, 20, 473); placeBit(matrix, 8, 20, 474); placeBit(matrix, 9, 19, 475); placeBit(matrix, 8, 19, 476); placeBit(matrix, 9, 18, 477); placeBit(matrix, 8, 18, 478); placeBit(matrix, 9, 17, 479); placeBit(matrix, 8, 17, 480); placeBit(matrix, 9, 16, 481); placeBit(matrix, 8, 16, 482); placeBit(matrix, 9, 15, 483); placeBit(matrix, 8, 15, 484); placeBit(matrix, 9, 14, 485); placeBit(matrix, 8, 14, 486); placeBit(matrix, 9, 13, 487); placeBit(matrix, 8, 13, 488); placeBit(matrix, 9, 12, 489); placeBit(matrix, 8, 12, 490); placeBit(matrix, 9, 11, 491); placeBit(matrix, 8, 11, 492); placeBit(matrix, 9, 10, 493); placeBit(matrix, 8, 10, 494); placeBit(matrix, 6, 10, 495); placeBit(matrix, 5, 10, 496); placeBit(matrix, 6, 11, 497); placeBit(matrix, 5, 11, 498); placeBit(matrix, 6, 12, 499); placeBit(matrix, 5, 12, 500); placeBit(matrix, 6, 13, 501); placeBit(matrix, 5, 13, 502); placeBit(matrix, 6, 14, 503); placeBit(matrix, 5, 14, 504); placeBit(matrix, 6, 15, 505); placeBit(matrix, 5, 15, 506); placeBit(matrix, 6, 16, 507); placeBit(matrix, 5, 16, 508); placeBit(matrix, 6, 17, 509); placeBit(matrix, 5, 17, 510); placeBit(matrix, 6, 18, 511); placeBit(matrix, 5, 18, 512); placeBit(matrix, 6, 19, 513); placeBit(matrix, 5, 19, 514); placeBit(matrix, 6, 20, 515); placeBit(matrix, 5, 20, 516); placeBit(matrix, 6, 21, 517); placeBit(matrix, 5, 21, 518); placeBit(matrix, 4, 21, 519); placeBit(matrix, 3, 21, 520); placeBit(matrix, 4, 20, 521); placeBit(matrix, 3, 20, 522); placeBit(matrix, 4, 19, 523); placeBit(matrix, 3, 19, 524); placeBit(matrix, 4, 18, 525); placeBit(matrix, 3, 18, 526); placeBit(matrix, 4, 17, 527); placeBit(matrix, 3, 17, 528); placeBit(matrix, 4, 16, 529); placeBit(matrix, 3, 16, 530); placeBit(matrix, 4, 15, 531); placeBit(matrix, 3, 15, 532); placeBit(matrix, 4, 14, 533); placeBit(matrix, 3, 14, 534); placeBit(matrix, 4, 13, 535); placeBit(matrix, 3, 13, 536); placeBit(matrix, 4, 12, 537); placeBit(matrix, 3, 12, 538); placeBit(matrix, 4, 11, 539); placeBit(matrix, 3, 11, 540); placeBit(matrix, 4, 10, 541); placeBit(matrix, 3, 10, 542); placeBit(matrix, 2, 10, 543); placeBit(matrix, 1, 10, 544); placeBit(matrix, 2, 11, 545); placeBit(matrix, 1, 11, 546); placeBit(matrix, 2, 12, 547); placeBit(matrix, 1, 12, 548); placeBit(matrix, 2, 13, 549); placeBit(matrix, 1, 13, 550); placeBit(matrix, 2, 14, 551); placeBit(matrix, 1, 14, 552); placeBit(matrix, 2, 15, 553); placeBit(matrix, 1, 15, 554); placeBit(matrix, 2, 16, 555); placeBit(matrix, 1, 16, 556); placeBit(matrix, 2, 17, 557); placeBit(matrix, 1, 17, 558); placeBit(matrix, 2, 18, 559); placeBit(matrix, 1, 18, 560); placeBit(matrix, 2, 19, 561); placeBit(matrix, 1, 19, 562); placeBit(matrix, 2, 20, 563); placeBit(matrix, 1, 20, 564); placeBit(matrix, 2, 21, 565); placeBit(matrix, 1, 21, 566); // ANSI escape codes for colors String blackBackground = "\u001B[48;5;16m "; // Black background "\u001B[48;5;16m " String whiteBackground = "\u001B[48;5;15m "; // White background "\u001B[48;5;15m " String yellowBackground = "\u001B[48;5;11m "; // Yellow background String redBackground = "\u001B[48;5;9m "; // Red background String reset = "\u001B[0m"; // Reset color // Display the matrix with colors System.out.println("QR Code:"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (matrix[i][j] == 1) { System.out.print(blackBackground); // Print with black background for 1 } else if (matrix[i][j] == 0) { System.out.print(whiteBackground); // Print with white background for 0 } else if (matrix[i][j] == 3) { System.out.print(yellowBackground); // Print with yellow background for 3 } else if (matrix[i][j] == 4) { System.out.print(redBackground); // Print with red background for 4 } } System.out.println(reset); // Reset colors at the end of each row } } public static void placeBit(int[][] QRCode, int y, int x, int value) { String text = MyClass.myNumber; // Get the bit value from the text string int bitValue = Character.getNumericValue(text.charAt(value)); // Flip the bit if (x + y) is odd if (((x) % 2 != 0)) { bitValue = 1 - bitValue; // Flip 0 to 1, or 1 to 0 } // Place the bit in the QRCode array QRCode[x][y] = bitValue; } public static String encodeToBinary(String input) { StringBuilder result = new StringBuilder(); // Step 1: Add Mode Indicator (Byte Mode) result.append("0100"); // Step 2: Add Character Count Indicator (8 bits for Version 3) result.append(toBinary(input.length(), 8)); // Step 3: Encode each character to 8-bit binary for (char c : input.toCharArray()) { result.append(toBinary(c, 8)); } // Step 4: Add Terminator (at least 4 bits) int terminatorBits = Math.min(4, 440 - result.length()); // Version 3 has a maximum of 440 bits for (int i = 0; i < terminatorBits; i++) { result.append('0'); } // Step 5: Pad to full byte (8-bit boundary) while (result.length() % 8 != 0) { result.append('0'); } result.append("00000000"); // Step 6: Add Padding Bytes (0xEC and 0x11 alternately) String paddingByte1 = "11101100"; // 0xEC String paddingByte2 = "00010001"; // 0x11 int currentBitLength = result.length(); while (currentBitLength < 440) { // Pad until we reach 440 bits result.append(paddingByte1); currentBitLength += 8; if (currentBitLength < 440) { result.append(paddingByte2); currentBitLength += 8; } } return result.toString(); } // Converts a binary string into an integer array. public static int[] convertBinaryToIntArray(String binaryData) { int length = binaryData.length() / 8; int[] intArray = new int[length]; for (int i = 0; i < length; i++) { intArray[i] = Integer.parseInt(binaryData.substring(i * 8, (i + 1) * 8), 2); } return intArray; } //Converts an integer to a binary string with a fixed number of bits. private static String toBinary(int value, int bitLength) { String binaryString = Integer.toBinaryString(value); while (binaryString.length() < bitLength) { binaryString = "0" + binaryString; } return binaryString; } //Formats the binary string by adding spaces between every byte (8 bits). private static String formatBinaryWithSpaces(String binary) { StringBuilder formattedBinary = new StringBuilder(); for (int i = 0; i < binary.length(); i += 8) { if (i > 0) { formattedBinary.append(' '); } formattedBinary.append(binary.substring(i, i + 8)); } return formattedBinary.toString(); } //Combines the original data and the error correction codewords into a final binary string. public static String combineDataAndErrorCorrection(String encodedData, int[] errorCorrection) { // Convert error correction integers to binary strings StringBuilder combinedData = new StringBuilder(encodedData); for (int ec : errorCorrection) { combinedData.append(toBinary(ec, 8)); // Convert each error correction word to 8-bit binary } combinedData.append("0000000"); return combinedData.toString(); } } class ReedSolomon { private static final int GF256_PRIMITIVE_POLY = 0x11D; // Irreducible polynomial x^8 + x^4 + x^3 + x + 1 private static final int FIELD_SIZE = 256; // GF(256) field private static final int[] EXP_TABLE = new int[FIELD_SIZE * 2]; private static final int[] LOG_TABLE = new int[FIELD_SIZE]; static { // Initialize the GF(256) field multiplication and division tables int x = 1; for (int i = 0; i < FIELD_SIZE; i++) { EXP_TABLE[i] = x; LOG_TABLE[x] = i; x <<= 1; if (x >= FIELD_SIZE) x ^= GF256_PRIMITIVE_POLY; } for (int i = FIELD_SIZE; i < FIELD_SIZE * 2; i++) { EXP_TABLE[i] = EXP_TABLE[i - FIELD_SIZE]; } } // Addition in GF(256) (XOR) public static int gfAdd(int a, int b) { return a ^ b; } // Multiplication in GF(256) public static int gfMultiply(int a, int b) { if (a == 0 || b == 0) return 0; return EXP_TABLE[(LOG_TABLE[a] + LOG_TABLE[b]) % (FIELD_SIZE - 1)]; } // Find the inverse of a number in GF(256) public static int gfInverse(int a) { if (a == 0) throw new ArithmeticException("Cannot invert zero."); return EXP_TABLE[FIELD_SIZE - 1 - LOG_TABLE[a]]; } // Generate the Reed-Solomon codewords (error correction codewords) public static int[] reedSolomonEncode(int[] data, int errorCorrectionLength) { int[] generator = generateGeneratorPolynomial(errorCorrectionLength); int[] encoded = Arrays.copyOf(data, data.length + errorCorrectionLength); for (int i = 0; i < data.length; i++) { int coef = encoded[i]; if (coef == 0) continue; for (int j = 0; j < generator.length; j++) { encoded[i + j] = gfAdd(encoded[i + j], gfMultiply(coef, generator[j])); } } return Arrays.copyOfRange(encoded, data.length, encoded.length); } // Generate the generator polynomial for the given error correction length private static int[] generateGeneratorPolynomial(int errorCorrectionLength) { int[] generator = {1}; for (int i = 0; i < errorCorrectionLength; i++) { int[] temp = {1, gfMultiply(EXP_TABLE[i], 1)}; generator = multiplyPolynomials(generator, temp); } return generator; } // Multiply two polynomials in GF(256) private static int[] multiplyPolynomials(int[] poly1, int[] poly2) { int[] result = new int[poly1.length + poly2.length - 1]; for (int i = 0; i < poly1.length; i++) { for (int j = 0; j < poly2.length; j++) { result[i + j] = gfAdd(result[i + j], gfMultiply(poly1[i], poly2[j])); } } return result; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue