printing format for hexadecimal signed number

printing format for hexadecimal signed number
# 1
11-05-2007
printing format for hexadecimal signed number

Hello Experts,,

I m facing a problem as follows.. need help..

When I am giving the below command it gives me three digit hexadecimal number , for ex :-

printf("%0.3x", 10);
Output: 00a

But I want the same for signed number also.

Now when I am specifiying the same format for singed number like

printf("%0.3x", -1 );

It gives me the output ffffffff

But I want only last 3 bytes ,ie fff

Last edited by user_prady; 11-05-2007 at 05:17 AM..
# 2
11-05-2007
Your conversion modifier is the problem. The 'x' conversion modifier takes an integer argument and converts it to unsigned lowercase hexadecimal notation.
 fpmurphy View Public Profile for fpmurphy Find all posts by fpmurphy
# 3
11-06-2007
Quote:
Originally Posted by fpmurphy
Your conversion modifier is the problem. The 'x' conversion modifier takes an integer argument and converts it to unsigned lowercase hexadecimal notation.

But I think its converting to a signed Hexadecimal number not to "unsigned lowercase hexadecimal " my friend..

as -1 in singed hexadecimal number is equal to ffffffff
and like wise if I will give printf("%x", -10);
which will give me a output fffffff6 . As -10 in signed hexadecimal number is equal to fffffff6 .

I think its depend on machine whether it is a 32 bit or 64 bit machine ,
But my problem is I want to take only the last 3 digits of the hexadecimal number ..
Ex: printf("%x", -10); sholud give me output ff6 not fffffff6 .

I am curious to know is there any format specifier in nawk or gawk in which I can get only the last three digits.
# 4
11-06-2007
There is no format in awk that permits to get only the last three last digit.
But you can write your own function, for example :

Input: Output: Jean-Pierre.
 aigles View Public Profile for aigles Find all posts by aigles
# 5
11-08-2007

Quote:
Originally Posted by aigles
There is no format in awk that permits to get only the last three last digit.
But you can write your own function, for example :

Input: Output: Jean-Pierre.
Thanks Genious Jean .. Where do you get these ideas..
# 6
11-08-2007
Quote:
Thanks Genious Jean .. Where do you get these ideas..
May I know the reason why did you use the below line
str = sprintf("%0" len "." len "x", number);
instead of just str = sprint("%x", number )

# 7
11-08-2007
Or directly:

Test Your Knowledge in Computers #147
Difficulty: Easy
Linus Torvalds released the Linux kernel as free software under the GNU General Public License in 1991.
True or False?

Printing df -h output in json format

Hi All, i am trying to print the df -h ouput in json format. using below script. #!/usr/bin/env bash df -h > /tmp/sdf nawk '{print " "\$1" "\$2" "\$3" "\$4" "\$5" "\$6" "}' /tmp/sdf > /tmp/sdf1 nawk 'NR==1 { for (i=1; i<=NF; i++) { f = i }}{ print \$(f), \$(f), \$(f), \$(f), ...

Help required in printing in specific format

Hi All, I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields. I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width...

Printing files in a specific format

Hi, I have following files in a directory with '.meta' extension, which have data in follwoing patterns. i need to print data from these files in below metioned format. please provide a script for this solution. file names: TEST_HISTORY_MTH.meta AB_TEST_1.meta cat...

Help with printing output format from a file

Hi, I need help in printing data in below format from file extensions with .dml, i have listed details below file name is test_temp.dml, location in /home/users/test01/test_temp.dml file content: sample_type= record decimal(",") test_type; date("DD-MM-YYYY")(",") test_date...

Printing records in different format

Hi all, I have a input file say record.txt hostname IP_address Port_No Version A 10.10.10.1 80 6.02 B 10.10.10.2 81 6.03 C 10.10.10.3 82 6.04 row 1 has 4 field headings : hostname, IP_address, Port_No and Version. and from 2nd row onwards the actual records start. now i need to...

Printing Number of Fields with the line number

Hi, How to print the number of fields in each record with the line number? Lets saw I have 3212|shipped|received| 3213|shipped|undelivered| 3214|shipped|received|delivered I tried the code awk -F '|' '{print NF}' This gives me ouput as 3 3 4

"Signed Linux" - Only executing signed programs

Hey folks, not sure whether this or the security board is the right forum. If I failed, please move :) So here's the problem: I need to build a Linux environment in which only "signed" processes are allowed to run. When I say signed I don't mean a VeriSign signature like you know it from...

Editing a UNIX file in Hexadecimal format

Hi, I am a newbie to the UNIX world. I am asked to edit the file in hexadecimal format and save it. Later I should be able to print the file in char mode. please anyone tell me how to do that mostly using VI editor.