Mobile phone short information SMS development - code, decoding

zhaozj2021-02-08  222

Mobile phone short information SMS development - code, decoding

1, English code

The default GSM character set is 7-bit encoding, the ASCII code is 8-bit encoding, and the encoding is converted to 7-bit encoding.

For example: 1234 After encoding 31d98c06

2 credit

8-bit codes 00110001 00110010 00110011 00110100

7-bit codes 00110001 11011001 10001100 00000110

As can be seen in an example, the BIT8 encoded by the ASCII8 bit is removed, and the last seven-bit encoding will move to the front, and the new 8-bit encoding is formed.

The following is the implementation code of C Builder:

String __stdcall encodeenglish (String InputStr)

{

INT N, LEN, CUR;

String Tempstr, Returnstr;

Unsigned char mid1 [2], mid2 [2];

Len = INPUTSTR.LENGTH ();

n = 0;

For (INT i = 1; i <= le; i )

{

IF (i

{Stracpy (MID1, INPUTSTR.SUBSTRING (I, 1) .c_str ()); STRCPY (MID2, INPUTSTR.SUBSTRING (i 1, 1) .c_str ()); CUR = (MID1 [0] >> N) ((MID2 [0] << (7-N)) & 0xFF);} else {structure (MID1, INPUTSTR.SUBSTRING (I, 1) .c_str ()); cur = (MID1 [0] >> N ) & 0x7f;} FMTSTR (Tempstr, "% 2.2X", arrayofconst ((CUR))); returnstr = returnstr Tempstr; n = (n 1)% 7; if (n == 0) i ;} return Returnstr;

2, English decoding is simply to convert 7-bit character encoding to 8 for character encoding below the implementation code of C Builder: int ReturnHex (int value) {switch (value) {cas 0: value = 0x7f; break; Case 1: Value = 0x3f; Break; Case 2: Value = 0x1f; Break; Case 3: Value = 0x0f; Break; Case 4: Value = 0x07; Break; Case 5: Value = 0x03; Break; Case 6: Value = 0x01; break; case 7: value = 0x00; break;} return value;} string __stdcall decodeenglish (string infutstr) {unsigned char INSTR [300]; char Outstr [300]; string str; int J = 0, i = 0 INT POINT = 0; int Temp; Memset (INSTR, 0, 301); MEMSET (Outstr, 0,301); for (int i = 0; i

{Str = "0x" inputstr.substring (i 1, 2); INSTR [I / 2] = start (STR);} while (j <= inputstr.length () / 2) {if (Point == 0) OUTSTR [I] = INSTR [J] & ReturnHex (Point); Else Outstr [I] = ((INSTR [J] & ReturnHex (POINT) <

> (8-point));

IF (POINT% 7 == 0 && Point! = 0) Point = 0; Else Point = Point 1; I ; J = I- (I / 8);

} Outstr [12] = ((INSTR [12] & 0x07) << 5) | (Instr [11] >> (8-5)); Return Ansistring (Outstr);} 3, Chinese code Chinese code is simpler, Converting the Chinese code of GB2312 into the code page for the cp936, which can be c builder implementation code string encodechinese (String INPUTSTR) {Int Cur; String Tempstr, Returnstr; WideString WS; Wchar_T MID [2]; WS = WIDESTRING (INPUTSTR); for (int i = 1; i <= ws.length (); i ) {wcscpy (MID, WS.SUBSTRING (I, 1) .c_bs ()); cur = mid [0]; FMTSTR (Tempstr, "% 4.4X", ArrayOfconst ((Cur))); Returnstr = Returnstr Tempstr;} Return Returnstr;} 4, Chinese decoding Unicode encoding of the code page as CP936 into the Chinese code of GB2312 can be Is C Builder implementation code string decodeChinese (String InputStr) {wchar_t buf [300]; for (int i = 0; i

{BUF [I / 4] = start ("0x" INPUTSTR.SUBSTRING (i 1, 4));} BUF [INPUTSTR.LENGTH () / 4] = 0; return widechartostring (buf);} Xue Changyu Changning @ YNMAIL.com redpower2004@21cn.com 2001-8-7

转载请注明原文地址:https://www.9cbs.com/read-2253.html

New Post(0)