Created
February 15, 2011 14:23
-
-
Save kalv/827580 to your computer and use it in GitHub Desktop.
Playing with hex and characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raw_data = <<-EOF | |
0000 0048 0000 0005 0000 0000 0000 0092 | |
0001 0134 3437 3739 3935 3734 3435 3200 | |
0101 3434 3739 3835 3133 3937 3331 0000 | |
0000 0000 0000 0000 0f41 626f 7574 20bb | |
3435 302c 3030 303f | |
EOF | |
raw_data = <<-EOF | |
0001 0134 3437 3739 3935 3734 3435 3200 | |
0101 3434 3739 3835 3133 3937 3331 0000 | |
0000 0000 0000 0000 0f41 626f 7574 20bb | |
3435 302c 3030 303f | |
EOF | |
kalv_data = <<-EOF | |
4c 6574 2773 2063 6865 636b 2074 6869 7320 bb32 2069 7320 7468 6520 7661 6c75 652e | |
EOF | |
#kalv_data = "bb" | |
hex_data = [kalv_data.chomp.gsub(" ","").gsub(/\n/,"")].pack("H*") | |
p hex_data | |
#[146, 0, "\000\001\001447799574452\000\001\001447985139731\000\000\000\000\000\000\000\000\000\000\017About \273450,000?"] | |
# p header = hex_data[0..15] | |
# len, cmd, status, seq = header.unpack('N4') | |
body = hex_data#[16..-1] | |
a = body.unpack('Z*CCZ*CCZ*CCCZ*Z*CCCCCa*') | |
sm_length = a[-2] | |
remaining_bytes = a[-1] | |
p a | |
short_message = remaining_bytes.slice!(0...sm_length) | |
# | |
p short_message.unpack('C*') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment