Mobile phone short information SMS development - code, decoding

xiaoxiao2021-03-05  22

Select Blog from Redpower

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

{

STRCPY (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

{

STRCPY (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

Simply put to convert 7-bit character encoding to 8 as character encoding

The following is the implementation code of C Builder:

int ReturnHex (int value)

{

Switch (Value)

{

Case 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 InputStr)

{

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] = STRTOINT (STR);

}

While (j <= INPUTSTR.LENGTH () / 2)

{

IF (Point == 0)

Outstr [I] = INSTR [J] & ReturnHex (POINT);

Else

Outstr [I] = ((Instr [J] & Returnhex (POINT)) << Point) | (INSTR [J-1] >> (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 coding is simpler, that is, convert GB2312 Chinese code to the code page as Unicode encoding of CP936.

The following is the implementation code of C Builder

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_bstr ());

Cur = MID [0];

FMTSTR (Tempstr, "% 4.4X", ArrayOfconst ((CUR));

Returnstr = Returnstr TempStr;

}

Return Returnstr;

}

4, Chinese decoding

Convert the code page for the Unicode encoding of the CP936 to GB2312.

The following is the implementation code of C Builder

String Decodeinese (String InputStr)

{

Wchar_t buf [300];

For (int i = 0; I

{

BUF [I / 4] = StrtOINT ("0x" InputStr.Substring (i 1, 4));

}

BUF [InputStr.Length () / 4] = 0;

Return Widechartostring (BUF);

}

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

{

STRCPY (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

{

STRCPY (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

Simply put to convert 7-bit character encoding to 8 as character encoding

The following is the implementation code of C Builder:

int ReturnHex (int value)

{

Switch (Value)

{

Case 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 InputStr)

{

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] = STRTOINT (STR);

}

While (j <= INPUTSTR.LENGTH () / 2)

{

IF (Point == 0)

Outstr [I] = INSTR [J] & ReturnHex (POINT);

Else

Outstr [I] = ((Instr [J] & Returnhex (POINT)) << Point) | (INSTR [J-1] >> (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 coding is simpler, that is, convert GB2312 Chinese code to the code page as Unicode encoding of CP936.

The following is the implementation code of C Builder

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_bstr ());

Cur = MID [0];

FMTSTR (Tempstr, "% 4.4X", ArrayOfconst ((CUR));

Returnstr = Returnstr TempStr;

}

Return Returnstr;

}

4, Chinese decoding

Convert the code page for the Unicode encoding of the CP936 to GB2312.

The following is the implementation code of C Builder

String Decodeinese (String InputStr)

{

Wchar_t buf [300];

For (int i = 0; I

{

BUF [I / 4] = StrtOINT ("0x" InputStr.Substring (i 1, 4));

}

BUF [InputStr.Length () / 4] = 0;

Return Widechartostring (BUF);

}

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

New Post(0)