Data representation: Binary, Binary Coded Decimal (BCD), ISO
Numeral presentation: Left-adjusted with trailing #F (where required)
Text presentation: Left-adjusted with trailing spaces (where required)
Filler: Spaces for ISO characters and #F for BCD numbers and TBCD string
0 1 Numeral 1 Record type, administrative data
ISO coded.
1 12 Identifier 1 - 12 characters Exchange Identity
12 most significant characters in the exchange identity.
ISO coded.
13 2 Digit string 00 - 99 Starting year for recording
ISO coded.
15 2 Digit string 01 - 12 Starting month for recording
ISO coded.
17 2 Digit string 01 - 31 Starting day for recording
ISO coded.
19 2 Digit string 00 - 23 Starting hour for recording
ISO coded.
21 2 Digit string 00 - 59 Starting minute for recording
ISO coded.
Thanks for any advice.
---------- Post updated at 10:50 PM ---------- Previous update was at 12:29 AM ----------
Maybe somebody can advise.
I only want to know if someone has used some binary parser that let me put in a template for each parameter within the file the number of bytes, type of encoding of each byte etc... I mean, put de description of each byte of groups of bytes in a template to be able to parse it.
Thanks for your help and for share that link, I'll check it!
The structure description is very long. But all is almost the same as the follwing description of the firsts bytes.
Position........Bytes........Value.....................................Field Description
0...................1...............Numeral 1..............................Record type, administrative data ISO coded.
1...................12..............Identifier 1 - 12 characters.....Site Identity (12 most significant characters in the site identity, ISO coded.)
13..................2...............Digit string 00 - 99.................Starting year for recording ISO coded.
15..................2...............Digit string 01 - 12.................Starting month for recording ISO coded.
17..................2...............Digit string 01 - 31.................Starting day for recording ISO coded.
19..................2...............Digit string 00 - 23.................Starting hour for recording ISO coded.
21..................2...............Digit string 00 - 59.................Starting minute for recording ISO coded.
Sorry, the below is a correct sample. I was doing some tests with the first sample and I changed bad the hex digits when I pasted here.
I read you code in the link you shared me. I see the code converts from hex each byte to decimal value to get the ascii char. But in
my file, some byte sequences BCD coded and should be interpreted as literal decimal values. For example the values highlighted in red
are the numbers 874401013008290 and 3742050001. Others are hexadecimal bytes sequences.
So, regarding the hexdump line below, how can I modifiy the hexdump command to print decimal values without convert it to hex value?,
I mean, when those sequences must be treated as decimal values literally.
If there is way to put in a template the rules defined in description of the file in how must be treated the sequences of bytes, I'll be able
to parse the binary file.
This should give you the _hex_ byte at position "$subscript" as a 2 byte text string.
This should correspond with the "values" you see but auto-changed to ASCII.
Just use a loop and concatenate that which you need...
I've been trying your code. But I'm not sure what happens when using the hexdump line you shared me in last post.
I want to interpret sequence of bytes as decimals (literal decimals). I'm using to test the code below:
start_offset=36
jump=1
last_byte_limit=43
for subscript in $( seq $start_offset $jump $last_byte_limit )
do
hextext=`hexdump -n1 -s$subscript -v -e '1/1 "%02x"' BinSample.dat`
char=$char`printf "%d" '0x'$hextext`
done
printf $char
The decimal sequence I would like to extract from the Binary sample in my previous post (in red) is from byte 36 to 43. The desired
result is: 87 44 01 01 30 08 29 0f. Exactly how it looks in hexdump, but the code is giving me another output (13568114884115)
and I don't know why.
(How is it that I, a mere amateur, is showing a professional the way?)
Once again think of your problem!
Did you ACTUALLY read my other reply correctly?
start_offset=36
jump=1
last_byte_limit=43
subscript=0
hextext=""
char=""
for subscript in $( seq $start_offset $jump $last_byte_limit )
do
hextext=`hexdump -n1 -s$subscript -v -e '1/1 "%02x"' BinSample.dat`
# NOTE! A (white)space is added as this is YOUR requirement.
char=$char" "$hextext
done
printf "$char"
I have not tested it but it should work...
EDIT:
Now tested on this Macbook Pro 22:42pm local UK time using the binary file generated in the original code:-
Last login: Tue May 21 18:19:33 on ttys000
Barrys-MacBook-Pro:~ barrywalker$ /Users/barrywalker/hextext.sh
db da d9 d8 d7 d6 d5 d4Barrys-MacBook-Pro:~ barrywalker$ _
Actually I'm not a proffesional in this area of programming or unix, in fact I'm a newbie in bash scripts. I only asking in the forum where experts could help.
Now my problem would be how to decode based on description, because sequences of bytes are interpreted sometimes as iso coded, sometimes as decimal values, sometimes as binary coded. I think here is where a template for parsing is needed but I don't know how to do it helping me with the hexdump command.
With hexdump, is possible convert an hex number like "A" into binary?
A=1010.
I really have no idea how to parse NIBBLES directly but this as a byte transfer should be a starter and splitting into two halve should be very easy...
Search the forums for more info on adding leading zeros, lower to upper case, etc...
It's all on here...
Research the bc command for more info:-
#!/bin/bash
# NOTE! Uppercase required...
for bits in 00 FF 55 AA
do
BITS=`echo "obase=2; ibase=16; $bits" | bc`
printf "$BITS\n"
done
Test using this Macbook Pro...
Last login: Wed May 22 07:12:22 on ttys000
Barrys-MacBook-Pro:~ barrywalker$ ./hextobit.sh
0
11111111
1010101
10101010
Barrys-MacBook-Pro:~ barrywalker$