Created
November 7, 2012 18:51
-
-
Save lgfa29/4033589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} else { | |
int myByte; | |
if (nbrBitsFilled == 0) | |
myByte = 0; | |
else | |
myByte = Integer.parseInt(myString.substring(nrBytesFilled*2, nrBytesFilled*2 + 2), 16); | |
String myByteString = Integer.toBinaryString(myByte); | |
myByteString = repeatString("0", nbrBitsFilled-myByteString.length()) + myByteString; | |
myByteString = reverseString(myByteString); | |
if (myByteString.equals("0")) | |
myByteString = "1"; | |
else | |
myByteString += "1"; | |
myByteString += repeatString("0", 8-nbrBitsFilled-1); | |
myByteString = reverseString(myByteString); | |
myString = myString.substring(0, nrBytesFilled*2) + String.format("%02X", Integer.parseInt(myByteString, 2)); | |
// adicionamos 00 até faltar um byte para alcançar o tamnho desejado (n-8 bits) | |
while((8*myString.length()/2) % n < n-8) { | |
myString += "00"; | |
} | |
// finalmente adicionamos o byte 0x80 para criar o padding 10*1 | |
myString += "80"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment