Jump to content


Photo

Reading hex


  • Please log in to reply
2 replies to this topic

#1 kardenal

kardenal
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 02 May 2006 - 08:26 AM

Hi. I'm trying to get PHP to read a hex value. This value comes from an SMS message sendt by a logger. It has information of energyusage. The information is sendt in hex and is 112 char long but PHP codes (pack) this into a 12 char long ASCII string and i can't find a way decode (unpack) this to its originale form. Does anyone have any idea how i can get hold of the initial hex value?

The SMS message: format definition from linux "gsmsmsd" command.

Type of message: SMS message
Message type: SMS-DELIVER
SC address: '4792001000'
More messages to send: 1
Reply path: 0
User data header indicator: 0
Status report indication: 0
Originating address: '4793002664'
Protocol identifier: 0x0
Data coding scheme: compressed fax message waiting
SC timestamp: 05/01/2006 12:00:27 AM (+0200)
User data length: [!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]112 [!--colorc--][/span][!--/colorc--]
User data header: 0x
User data: '[!--coloro:#CC0000--][span style=\"color:#CC0000\"][!--/coloro--]m741007ë,W[!--colorc--][/span][!--/colorc--]

The "m741007ë,W" is a representation of the 112 chr hex string.

The hex is 16 based.

Anyone???


#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 02 May 2006 - 11:45 AM

As far as I can work out, the 11 character ASCII string 'm741007ë,W would only convert to a 33 character hexadecimal string. Printable ASCII characters are 3 hex characters long I think. Can you post up any code that you are using to receive the user data?

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 May 2006 - 02:07 PM

You are probably echoing the "User data string" and since it looks like the information contains binary (i.e. non characters) it most likely has some NULL characters (all zeroes) which stops a normal character string.

Take a look at the functions [a href=\"http://www.php.net/pack\" target=\"_blank\"]pack()[/a] and [a href=\"http://www.php.net/bin2hex\" target=\"_blank\"]bin2hex()[/a]. One of them should give you what you're looking for.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users