How to print 32 bit value complete?

1

I want to know that how to print the complete integer value with zero also in C only.

And i am in kernel space ,want to print some values in kernel module.

Like if a is a 32 bit integer then

int a = 14

then output will be like this

value of a = 0x0000000e

in hexa-decimal.

Thanks in advance.

c
kernel
hex
asked on Stack Overflow May 4, 2013 by goodies • edited May 4, 2013 by goodies

2 Answers

15

Put a 0 in the format:

printf("value of a = 0x%08x", a);

From the printf(3) man page:

'0' (zero)

Zero padding. For all conversions except n, the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, i, o, u, i, x, and X), the 0 flag is ignored.

Nothing like the documentation to answer questions for you - at least if the documentation is any good.

answered on Stack Overflow May 4, 2013 by Carl Norum • edited May 4, 2013 by Carl Norum
1
#include <stdio.h>

int main(int argc, char *argv[])
{
  int a = 14;

  printf("value of a = 0x%08x\n", a);

  return 0;
}
answered on Stack Overflow May 4, 2013 by John Leimon

User contributions licensed under CC BY-SA 3.0