tech_log: July 2009

Thursday, July 16, 2009

Selecting previous code chunks from svn for copy/paste

You want to select and copy paste chunks of code from previous svn revision, but svn diff marks changes with "+ " or "-" in the beginnig of each line. In trac, lines are prefixed with line numbers, so selct will pick up these also.

We want a chunk of what was in previous revision, but easy to select/copy/paste:

drasko@marx:~/u-boot$ svn diff -r HEAD:PREV --diff-cmd diff -x -n common/cmd_spidboot.c

Use:
drasko@marx:~/u-boot$ svn help diff
and:
drasko@marx:~/u-boot$ man diff
to see what the command means, but basically it tells svn to use diff command with specific switches.

If you want to select only new changes, change HEAD:PREV to PREV:HEAD



Friday, July 10, 2009

Numbers in different formats from command line

HEX -> BASE OF 2
In order to quickly view a hex number in binary format from a command line there is a little trick.
xxd can be used to hexdump a bin file, but also to do reverse - to create a binary file out of hexdump format. Well, hexdump format looks like this :
0000000: 12 ff 3e
That means in this format:
<offset>: <byte> <byte> ...
This is the format that xxd -r will take and produce bin output.
Adding -p option, we can write hexdump in this format:
<byte><byte>...
That means that file with this content :
31 32 31
given to xxd -r -p test.txt > hex.bin
will produce hex.bin with these contents:
121
i. e. real binary values will be showed, and Vi will print these chars as "1" (ascii value 31),"2" (ascii value 32), "1".
hd will hexdump this bin file backward again, and present it in the hexdump format:
drasko@Marx:~/video$ hd hex.bin
00000000  31 32 31                                          |121|
00000003

That gives the idea to use xdd to transform number in hexadecimal format actually into bin, and analyze that bin via hd or xdd again, to represent it back in hexdump value, only this time we can add switches how we want this bin value to be showed.
For example:
drasko@Marx:~$ xxd -r -p | xxd
0a           <------------- enter 0a and press <ENTER>, and after CTRL+D here to give EOF
0000000: 0a                                       .
drasko@Marx:~$

Cool. Let's try to give a switch to second xxd to make it represent given binary into base 2 format:

drasko@Marx:~$ xxd -r -p | xxd -b
0a
0000000: 00001010                                               .

NOTE:
We must always enter hex nuber in byte-per-byte format, because this is hexdump format that xxd is expecting. We cannot do :
drasko@Marx:~$ xxd -r -p | xxd
238
0000000: 23                                       #
because produced binary will be just one byte,  0x23, and when we represent that in base 2, results will not be what we wanted:
drasko@Marx:~$ xxd -r -p | xxd -b
238
0000000: 00100011

We actually wanted this :
drasko@Marx:~$ xxd -r -p | xxd -b
0238
0000000: 00000010 00111000                                      .8
drasko@Marx:~$

HEX -> BASE OF 10 (and back)
Use python interpreter for this:
drasko@Marx:~$ python
Python 2.5.2 (r252:60911, Sep 29 2008, 21:15:13)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0x32
50
>>> hex(50)
'0x32'
>>>