OK, now that I see what you're doing...a couple commnents. First, expand your array to 128 values minimum to make the 64 bit case work. 110 is too small. Here's the main algorithm you want to use. I took the liberty to change the variable name pointer
to parity
, and removed some extra variables like iterator
. This should be close to what you need. Check for "one off" errors and 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
{
for (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. Now skip the 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