Win a copy of Terraform in Action this week in the Cloud forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Rob Spoor
• Bear Bibeault
Saloon Keepers:
• Jesse Silverman
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Carey Brown
Bartenders:
• Piet Souris
• Al Hobbs
• salvin francis

# OCTET Convert to Timezone

Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
I have a value in OCTET string such as 23 00

MSTimeZone ::= OCTET STRING (SIZE (2))
--
-- 1.Octet: Time Zone and 2. Octet: Daylight saving time, see TS 29.060 [75]
--

output Format of Timezone is “xHHMM”. “x” means GTM + or GTM -, HHMM means hour and minute.

so in this case,

2300 equals to output GTM+8h0m

What happen and how this translate comes from?

Marshal
Posts: 3727
534
• 1
• Number of slices to send:
Optional 'thank-you' note:
First Octet
The first octet is the time zone offset from UTC in 15 minute steps.  In your example, the hex value is 23

The octet contains 2 nibbles (4-bit values), with the MS (most significant) nibble on the right, and the LS (least significant) nibble on the right:
Hex:     2    3
Binary: 0010 0011

Swap them to put the MS nibble on the left and the LS on the right:
Hex:     3    2
Binary: 0011 0010

The most left-most bit is a sign bit which indicates if the offset is + (0) or - (1)
0 => + offset

The remainder of the bits represent a BCD (binary coded decimal) number of offset steps
011 0010 => 32 decimal

32 steps of 15 minutes => 8h0m

Signed offset: +8h0m offset from UTC

Second Octet
The second octet indicates the number of hours of adjustment due to daylight savings

The 2 LS bits represent the adjustment:

Alex Lee
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:
The remainder of the bits represent a BCD (binary coded decimal) number of offset steps
011 0010 => 32 decimal

I have one question

I can get 0110010 -> 32 hexadecimal (but not decimal)
Is it true 011 0010 => 32 hexadecimal?

Alex Lee
Ranch Hand
Posts: 33
• Number of slices to send:
Optional 'thank-you' note:

Alex Lee wrote:The remainder of the bits represent a BCD (binary coded decimal) number of offset steps
011 0010 => 32 decimal

I have one question

I can get 0110010 -> 32 hexadecimal (but not decimal)
Is it true 011 0010 => 32 hexadecimal?

000110010 = (0 × 2⁸) + (0 × 2⁷) + (0 × 2⁶) + (1 × 2⁵) + (1 × 2⁴) + (0 × 2³) + (0 × 2²) + (1 × 2¹) + (0 × 2⁰) = 50

Saloon Keeper
Posts: 13420
300
• 1
• Number of slices to send:
Optional 'thank-you' note:
It's BCD: each quartet represents a decimal digit.

Ron McLeod
Marshal
Posts: 3727
534
• 1
• Number of slices to send:
Optional 'thank-you' note:
Binary coded decimal (BCD) is a way of storing decimal digits 0 through 9 using a binary form.  BCD is often used with display devices with have limited or no processing capabilities.  It is also used is a lot of telephony signalling protocols, like the GSM protocol you are working with.  In telephony the two digits are generally packed in to a single octet, so when you see a value like 0011 0010, you need to evaluate the two 4-bit sections of the octet individually as two separate digits; not as one 8-bit value.

0011 represents the digit 3
0010 represents the digit 2

Here's another example which might help - counting from 0 to 25, using packed BCD:
Decimal     BCD
0     0000 0000
1     0000 0001
2     0000 0010
3     0000 0011
4     0000 0100
5     0000 0101
6     0000 0110
7     0000 0111
8     0000 1000
9     0000 1001
10     0001 0000
11     0001 0001
12     0001 0010
13     0001 0011
14     0001 0100
15     0001 0101
16     0001 0110
17     0001 0111
18     0001 1000
19     0001 1001
20     0010 0000
21     0010 0001
22     0010 0010
23     0010 0011
24     0010 0100
25     0010 0101

 You showed up just in time for the waffles! And this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton