java - Loop cuts last two groups of my array, when it outputs values -


i have tab[110] array random 1 , 0 ints, so: 1001111001011110... , on untill end of array. trying output 7 different rows of bits according hamming code. loop works groups starting bits, index in array 2,4,8,16. 32th loop cuts half of them (so start output 64, not 32) , group 64th skipped completely.

int x=0;         int sum=0;         int pointer=0;         boolean w = true;         system.out.println("grupy bitow parzystych");          (int i=2; i<=7; i++)         {              system.out.println("\n");              switch(i)              {                 //case 1: pointer=1;                    case 2: pointer=2;                      break;                  case 3: pointer=4;                      break;                  case 4: pointer=8;                      break;                  case 5: pointer=16;                      break;                  case 6: pointer=32;                      break;                  case 7: pointer=64;                      break;                  default: system.out.println("default switch");                      break;              }              sum=0;             x=0;             (int p=0; p<tab.length; p++)              {                 if (p==0) system.out.println("grupa bitow: "+pointer);                 if (p<=pointer-1) continue;                 x++;                 if (x == pointer)                     {                         x = 0;                         w = !w;                     }                          if (p%20==0) system.out.println("");                         if (w)                      {                         iterator = p+1;                         system.out.print(tab[p]+"("+iterator+")"+",");                         sum++;                     }                 if (p==tab.length-1) system.out.println("suma bitow pary "+pointer+": "+sum);             }         } 

ok, see you're doing...a couple commnents. first, expand array 128 values minimum make 64 bit case work. 110 small. here's main algorithm want use. took liberty change variable name pointer parity, , removed variables iterator. should close need. check "one off" errors , such.

        switch(i)         {         //case 1: pointer=1;           case 2: parity=2;         break;         case 3: parity=4;         break;         case 4: parity=8;         break;         case 5: parity=16;         break;         case 6: parity=32;         break;         case 7: parity=64;         break;         default: system.out.println("default switch");         break;         }          system.out.println("grupa bitow: "+parity);         sum=0;         int index = parity - 1;         int blocksize = parity;         int printcount = 0;          while (index + blocksize < tab.length) //don't run past end of bit array         {             (int j = 0; j < blocksize; j++)              {                 if (printcount++ % 20 == 0)                     system.out.println("");                  system.out.print(tab[index] + "(" + (index + 1) + ")" + ",");                 sum += tab[index++];             }             //printing of consecutive bits complete. skip next 2|4|8|16|32|64 bits             index += blocksize;         }         system.out.println("\n\nsuma bitow pary " + parity  + ": " + sum);     } 

output:

grupy bitow parzystych

grupa bitow: 2

0(2),0(3),1(6),0(7),1(10),0(11),0(14),0(15),1(18),0(19),0(22),0(23),1(26),1(27),0(30),1(31),0(34),0(35),1(38),1(39), 0(42),0(43),0(46),0(47),0(50),0(51),0(54),0(55),0(58),0(59),0(62),1(63),1(66),0(67),0(70),1(71),0(74),1(75),0(78),1(79), 1(82),0(83),0(86),0(87),1(90),1(91),0(94),1(95),0(98),1(99),1(102),1(103),1(106),0(107),0(110),0(111),0(114),0(115),0(118),0(119), 0(122),0(123),0(126),0(127),

suma bitow pary 2: 21

grupa bitow: 4

0(4),0(5),1(6),0(7),0(12),1(13),0(14),0(15),1(20),1(21),0(22),0(23),1(28),1(29),0(30),1(31),1(36),0(37),1(38),1(39), 0(44),1(45),0(46),0(47),0(52),1(53),0(54),0(55),1(60),0(61),0(62),1(63),1(68),0(69),0(70),1(71),1(76),0(77),0(78),1(79), 1(84),0(85),0(86),0(87),0(92),1(93),0(94),1(95),1(100),1(101),1(102),1(103),0(108),0(109),0(110),0(111),0(116),0(117),0(118),0(119), 0(124),0(125),0(126),0(127),

suma bitow pary 4: 25

grupa bitow: 8

0(8),0(9),1(10),0(11),0(12),1(13),0(14),0(15),1(24),0(25),1(26),1(27),1(28),1(29),0(30),1(31),1(40),0(41),0(42),0(43), 0(44),1(45),0(46),0(47),1(56),0(57),0(58),0(59),1(60),0(61),0(62),1(63),1(72),0(73),0(74),1(75),1(76),0(77),0(78),1(79), 0(88),0(89),1(90),1(91),0(92),1(93),0(94),1(95),0(104),0(105),1(106),0(107),0(108),0(109),0(110),0(111),0(120),0(121),0(122),0(123), 0(124),0(125),0(126),0(127),

suma bitow pary 8: 22

grupa bitow: 16

1(16),0(17),1(18),0(19),1(20),1(21),0(22),0(23),1(24),0(25),1(26),1(27),1(28),1(29),0(30),1(31),0(48),0(49),0(50),0(51), 0(52),1(53),0(54),0(55),1(56),0(57),0(58),0(59),1(60),0(61),0(62),1(63),1(80),1(81),1(82),0(83),1(84),0(85),0(86),0(87), 0(88),0(89),1(90),1(91),0(92),1(93),0(94),1(95),0(112),0(113),0(114),0(115),0(116),0(117),0(118),0(119),0(120),0(121),0(122),0(123), 0(124),0(125),0(126),0(127),

suma bitow pary 16: 22

grupa bitow: 32

0(32),1(33),0(34),0(35),1(36),0(37),1(38),1(39),1(40),0(41),0(42),0(43),0(44),1(45),0(46),0(47),0(48),0(49),0(50),0(51), 0(52),1(53),0(54),0(55),1(56),0(57),0(58),0(59),1(60),0(61),0(62),1(63),1(96),0(97),0(98),1(99),1(100),1(101),1(102),1(103), 0(104),0(105),1(106),0(107),0(108),0(109),0(110),0(111),0(112),0(113),0(114),0(115),0(116),0(117),0(118),0(119),0(120),0(121),0(122),0(123), 0(124),0(125),0(126),0(127),

suma bitow pary 32: 17

grupa bitow: 64

0(64),1(65),1(66),0(67),1(68),0(69),0(70),1(71),1(72),0(73),0(74),1(75),1(76),0(77),0(78),1(79),1(80),1(81),1(82),0(83), 1(84),0(85),0(86),0(87),0(88),0(89),1(90),1(91),0(92),1(93),0(94),1(95),1(96),0(97),0(98),1(99),1(100),1(101),1(102),1(103), 0(104),0(105),1(106),0(107),0(108),0(109),0(110),0(111),0(112),0(113),0(114),0(115),0(116),0(117),0(118),0(119),0(120),0(121),0(122),0(123), 0(124),0(125),0(126),0(127),

suma bitow pary 64: 23


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -