goodies
goodies

Reputation: 543

How to print 32 bit value complete?

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.

Upvotes: 2

Views: 38134

Answers (3)

Alok Pindoriya
Alok Pindoriya

Reputation: 1

//print 32 bit no in hex
 uint32_t n = 0x10203040;
 printf("32_bit no 0x%08x",n);


32_bit no 0x10203040

Upvotes: -2

Carl Norum
Carl Norum

Reputation: 225132

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.

Upvotes: 17

John Leimon
John Leimon

Reputation: 1091

#include <stdio.h>

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

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

  return 0;
}

Upvotes: 0

Related Questions