my app work smsc, , need involve in sms before send,
i try send mobile string
"hello test"
and when check smsc got binary string of text:
userdata = "c8329bfd06d1d1e939283d07d1cb733a"
the encoding of string is:
<encoding:ascii-8bit>
i know userdata in gsm encoding in binary-string
so how can userdata clear text string ?
this question english lang, because in hebrew can string code:
[userdata].pack('h*').force_encoding('utf-16be').encode('utf-8')
but in english got error:
encoding::invalidbytesequenceerror: "\xda\xf3" followed "u" on utf-16be
what try detect binary string icu, , got:
"iso-8859-1" , language detected is: 'pt', strange cause languages english or hebrew.
anyway got lost encoding stuff, try encode each name of list encoding.list
but without luck until now
thanks in advance
shmulik
ok,
for have issue, got solution, #ruby irc community (i missed nickname)
the solution is:
for ascii chars interpolate binary:
you need that:
"c8329bfd06d1d1e939283d07d1cb733a".scan(/../).reverse_each.map { |h| h.to_i(16) }.pack('c*').unpack('b*')[0][2..-1].scan(/.{7}/).map.with_object("") { |x, s| s << x.to_i(2) }.reverse
remember sent words in sms:
"hello test"
and has become in binary to:
"c8329bfd06d1d1e939283d07d1cb733a"
the reason got garbage in encoding is, because ascii chars 7bits gsm, first 7bits represents data each encoding uses @ least 8bits, code do.
but ascii char set.
in language use hebrew, sms send ucs2
so code work me:
[your_binary_string].pack('h*').force_encoding('utf-16be').encode('utf-8')
very important put binary string in array
so now.
if want translate , explain happen in code ascii char set, guest , welcome.
shmulik
Comments
Post a Comment