Data Pattern generation

D

Deepu

Hi All,

I am trying to generate data in the pattern shown below, can somebody
please help me giving some ideas on how it can be generated.

Data Pattern required:

0x000000 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0006 0x0007
0x0008 ------- 0x000f
0x000010 0x0010 0x0011 0x0012 0x0013 0x0014 0x0015
------------------------------------------ 0x001f
0x000020
|
|
0x000100 0x0100 0x0101 0x0102
 
U

usenet

Deepu said:
I am trying to generate data in the pattern shown below, can somebody
please help me giving some ideas on how it can be generated.
...
0x000100 0x0100 0x0101 0x0102

I assume you are asking how to print a group of decimal numbers in hex
format...

use printf. For example, to print the sample line quoted above:

printf "%0#8x %0#6x %0#6x %0#6x\n", qw{256 256 257 258};

The format string '%0#8x' says:
% - all format strings begin with %
0 - uses leading zeros (instead of space)
# - prefix non-zero number with '0x' (for hex numbers)
8 - number field is minimum 8 characters long
x - unsigned hex integer (lowercase)
 
D

Deepu

The best way to get a good answer is to ask a good question.
Sorry for my improper description. I am trying to auto generate this
pattern

0x000000 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0006 0x0007
0x000008 0x0008 0x0009 0x000a 0x000b 0x000c 0x000d 0x000e 0x000f
0x000010 0x0010 0x0011 0x0012 0x0013 0x0014 0x0015 0x0016 0x0017
0x000018 0x0018 0x0019 0x001a 0x001b 0x001c 0x001d 0x001e 0x001f

this sequential pattern continues till the ADDR becomes 0x000100

The first column basically represent ADDR(address) and the column after
that represent the data.

This is basically equivalent to:
0x000000 has 0x0000
0x000001 has 0x0001
and so on.

Thanks for your time.
 
D

Dr.Ruud

(e-mail address removed) schreef:
The format string '%0#8x' says:
% - all format strings begin with %
0 - uses leading zeros (instead of space)
# - prefix non-zero number with '0x' (for hex numbers)
8 - number field is minimum 8 characters long
x - unsigned hex integer (lowercase)

The documentation of sprintf is a little bit (sic) off regarding the
"0x" prefix, because it can be "0X" too:

$ perl -we 'printf "%#04X\n", 15'
0X0F

$ perl -we 'printf "%0#4X\n", 15'
0X0F


I tend to use:

$ perl -we 'printf "0x%02X\n", 15'
0x0F

because I like to use that format, and because I easily forget to count
in the "0x" prefix (in the length).


The following is a bit harder to convert to a lowercase prefix and
uppercase numerics:

$ perl -we 'printf "%#8.2x\n", 15'
0x0f



The documentation is already updated for the next release of perl,
saying that the casing of the prefix follows the casing of the
conversion-letter.


See also:

$ perl -we 'printf "%#08b\n", 15'
0b001111

The uppercase-B is added to the next release of perl:

$ perl5.9 -we 'printf "%#08B\n", 15'
0B001111

Maybe one day there will be a %P (and maybe even a %#p) too.
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top