# [RESOLVED] SMS PDU Calculation

• Feb 7th, 2018, 10:51 PM
aq_mishu
[RESOLVED] SMS PDU Calculation
Guyz,
What is the meaning of it?? I need a strip down of it...:

Code:

`PDUCodes(i).Length - Val("&H" & Mid(PDUCodes(i), 1, 2)) * 2 - 2) / 2`
PDUCodes(i) is a loooong hex string of SMS PDU. That's for sure... Like:

Code:

`07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E`
and the final result should come 42 after this calculation.

Ref: http://www.developershome.com/sms/cmgsCommand4.asp

Mshu~
• Feb 8th, 2018, 11:01 AM
si_the_geek
Re: SMS PDU Calculation
This part: Mid(PDUCodes(i), 1, 2)
...gets the first two characters of PDUCodes(i), so is the same as "07"

This part: Val("&H" & "07")
...gets the numerical value of the Hex value (converted to decimal), so in this case 7.

The rest is simple maths, so you can probably work all that out yourself.
• Feb 8th, 2018, 11:24 AM
passel
Re: SMS PDU Calculation
Quote:

Originally Posted by aq_mishu
...
and the final result should come 42 after this calculation.
...

I tested it and the final result is 42, so the code works.
• Feb 8th, 2018, 12:38 PM
aq_mishu
Re: SMS PDU Calculation
Quote:

Originally Posted by si_the_geek

The rest is simple maths, so you can probably work all that out yourself.

If i'm not that stupid in maths:

Code:

`(PDUCodes(i).Length - Val("&H" & Mid(PDUCodes(i), 1, 2)) * 2 - 2) / 2`
for
Code:

`07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E`
= 100 chars

VAL(&H07) = 07

hence it is: (100 - (7*2-2))/2 = (100 - 12)/2 = 44

????????
• Feb 8th, 2018, 02:15 PM
passel
Re: SMS PDU Calculation
It isn't (100 - (7*2-2))/2 = (100 - 12)/2 = 44
its (100 - (7)*2-2)/2 i.e. (100 - 7 * 2 - 2) / 2

Code:

```(PDUCodes(i).Length - Val("&H" & Mid(PDUCodes(i), 1, 2)) * 2 - 2) / 2 (      100        -    (              7            ) * 2 - 2) / 2```
If you type in your immediate window...
? (100 - 7 * 2 - 2)/2
you get
42

The order of operations is:
Code:

```(100 - 7 * 2 - 2) / 2 (100 -  14  - 2) / 2 (  86      - 2) / 2 (      84      ) / 2         42```
• Feb 8th, 2018, 04:45 PM
aq_mishu
Re: SMS PDU Calculation
OKdoki!!

Yep!! I discovered it after you said... p a r e n t h e s i s huh!!