Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

binary format - understanding output.

Status
Not open for further replies.

nu2tcl

Programmer
Aug 24, 2013
1
0
0
IN
Hi All,
I am new to TCL and going through the binary format command. I am just trying to see how this command works. So I wrote few statements and directed the output to a file. Using hex edit I looked through the content but they are not as expected or may be I am not doing it right. Request you help me with my understanding. thanks .

Code:
#!/usr/bin/tclsh
set a [binary format B2 10 ]
puts $a
set a [binary format h4 abcd]
puts $a

set b "Hello World"
puts $b

output
Code:
C2 80 0A C2  BA C3 9C 0A  48 65 6C 6C  6F 20 57 6F  72 6C 64 0A
I understand that puts by default adds a newline, so 0A is the delimiter in my output.
my first statement in code i.e., binary format B2 10, as per my understanding, I thought it should give out x/80. But in my output I see an additional X/C2. Not sure why?
my third statement in code i.e., binary format h4 abcd, as per my understanding, I thought I should get x/ba x/cd, but I see again x/C2 x/BA x/C3 x/9C.

So I think I have got a complete wrong understanding from the manual. Any help is greatly appreciated.

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top