The octets from “Hello world” are: E8 32 9B FD 06 DD DF 72 36 19
And if apply padding it will become : D0 65 36 FB 0D BA BF E5 6C 32
(copy from wiki)
Can I know what’s the formula to encoding with 1-bit padding?
Here is the formula of convert string to PDU that I edited :(thanks to source provider)
*The whole complete formula is kinda long so I just post a part of it here…
maxkeys = 160;
function binToInt(x)//sp
{
var total = 0;
var power = parseInt(x.length)-0;
for(var i=0;i<x.length;i++)
{
if(x.charAt(i) == '1')
{
total = total +Math.pow(2,power);
}
power --;
}
return total;
}
function intToHex(i) //sp
{
var sHex = "0123456789ABCDEF";
h = "";
i = parseInt(i);
for(j = 0; j <= 3; j++)
{
h += sHex.charAt((i >> (j * 8 + 4)) & 0x0F) +
sHex.charAt((i >> (j * 8)) & 0x0F);
}
return h.substring(0,2);
}
function stringToPDU(inpString,size)
{
var bitSize = size[0].value * size[0].checked | size[1].value * size[1].checked | size[2].value * size[2].checked;
var octetFirst = "";
var octetSecond = "";
var output = "";
var DATA_ENCODING = "00";
var VALID_PERIOD = "AA";
var userDataSize;
if (bitSize == 7)
{
userDataSize = intToHex(inpString.length);
for(var i=0;i<=inpString.length;i++)
{
if(i==inpString.length)
{
if (octetSecond != "") // AJA Fix overshoot
{
output = output + "" + (intToHex(binToInt(octetSecond)));
}
break;
}
var current = intToBin(getSevenBit(inpString.charAt(i)),7);
var currentOctet;
if(i!=0 && i%8!=0)
{
octetFirst = current.substring(7-(i)%8);
currentOctet = octetFirst + octetSecond;
output = output + "" + (intToHex(binToInt(currentOctet)));
octetSecond = current.substring(0,7-(i)%8);
}
else
{
octetSecond = current.substring(0,7-(i)%8);
}
}
}
//var data = DATA_ENCODING + VALID_PERIOD + userDataSize;
var PDU = output;
return PDU;
}
<input onclick="pduOut.value= stringToPDU(document.stringToPduForm.smsText.value.substring (0, maxkeys),document.stringToPduForm.size);" type="button" size="11" value=" Convert " name="stringButton">
I need to know what changes needed so that the formula can encode message with 1-bit padding..but I not really understand the concept,can someone teach me?
Thanks.
Write out those octets in binary (with the lowest bit first in each octet) and you’ll see it: