@@ -363,53 +363,55 @@ static String toString(Bytes bytes) {
363363 }
364364
365365 /**
366- * Shifts input byte array shiftBitCount bits left. This method will alter the input byte array.
366+ * Light shift of whole byte array by shiftBitCount bits.
367+ * This method will alter the input byte array.
367368 */
368- static byte [] shiftLeft (byte [] data , int shiftBitCount ) {
369- final int shiftMod = shiftBitCount % 8 ; //6 % 8 = 2
370- final byte carryMask = (byte ) ((1 << shiftMod ) - 1 ); // 0000 0010 << 2 = 0000 1000 - 0000 0001 = 0000 0111
371- final int offsetBytes = (shiftBitCount / 8 ); // = 0
369+ static byte [] shiftLeft (byte [] byteArray , int shiftBitCount ) {
370+ final int shiftMod = shiftBitCount % 8 ;
371+ final byte carryMask = (byte ) ((1 << shiftMod ) - 1 );
372+ final int offsetBytes = (shiftBitCount / 8 );
372373
373374 int sourceIndex ;
374- for (int i = 0 ; i < data .length ; i ++) {
375+ for (int i = 0 ; i < byteArray .length ; i ++) {
375376 sourceIndex = i + offsetBytes ;
376- if (sourceIndex >= data .length ) {
377- data [i ] = 0 ;
377+ if (sourceIndex >= byteArray .length ) {
378+ byteArray [i ] = 0 ;
378379 } else {
379- byte src = data [sourceIndex ];
380+ byte src = byteArray [sourceIndex ];
380381 byte dst = (byte ) (src << shiftMod );
381- if (sourceIndex + 1 < data .length ) {
382- dst |= data [sourceIndex + 1 ] >>> (8 - shiftMod ) & carryMask ;
382+ if (sourceIndex + 1 < byteArray .length ) {
383+ dst |= byteArray [sourceIndex + 1 ] >>> (8 - shiftMod ) & carryMask ;
383384 }
384- data [i ] = dst ;
385+ byteArray [i ] = dst ;
385386 }
386387 }
387- return data ;
388+ return byteArray ;
388389 }
389390
390391 /**
391- * Shifts input byte array shiftBitCount bits right. This method will alter the input byte array.
392+ * Unsigned/logical right shift of whole byte array by shiftBitCount bits.
393+ * This method will alter the input byte array.
392394 */
393- static byte [] shiftRight (byte [] data , int shiftBitCount ) {
395+ static byte [] shiftRight (byte [] byteArray , int shiftBitCount ) {
394396 final int shiftMod = shiftBitCount % 8 ;
395397 final byte carryMask = (byte ) (0xFF << (8 - shiftMod ));
396- final int offset = (shiftBitCount / 8 );
398+ final int offsetBytes = (shiftBitCount / 8 );
397399
398400 int sourceIndex ;
399- for (int i = data .length - 1 ; i >= 0 ; i --) {
400- sourceIndex = i - offset ;
401+ for (int i = byteArray .length - 1 ; i >= 0 ; i --) {
402+ sourceIndex = i - offsetBytes ;
401403 if (sourceIndex < 0 ) {
402- data [i ] = 0 ;
404+ byteArray [i ] = 0 ;
403405 } else {
404- byte src = data [sourceIndex ];
406+ byte src = byteArray [sourceIndex ];
405407 byte dst = (byte ) ((0xff & src ) >>> shiftMod );
406408 if (sourceIndex - 1 >= 0 ) {
407- dst |= data [sourceIndex - 1 ] << (8 - shiftMod ) & carryMask ;
409+ dst |= byteArray [sourceIndex - 1 ] << (8 - shiftMod ) & carryMask ;
408410 }
409- data [i ] = dst ;
411+ byteArray [i ] = dst ;
410412 }
411413 }
412- return data ;
414+ return byteArray ;
413415 }
414416
415417 /*
0 commit comments