Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

OCTET Convert to Timezone  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Could anyone help to advise?


 
Saloon Keeper
Posts: 2261
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
00: no adjustment
01: +1 hour adjustment
10: +2 hours adjustment
 
Alex Lee
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 9558
189
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's BCD: each quartet represents a decimal digit.
 
Ron McLeod
Saloon Keeper
Posts: 2261
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!