Question: so I have this code

```
int main()
{
  int n, c, k;

  printf("Enter an integer\n");
  scanf("%d", &n);

  printf("%d in binary is:\n", n);

  for (c = 31; c >= 0; c--)
  {
    k = n >> c;

    if (k & 1)
      printf("1");
    else
      printf("0");
  }

  printf("\n");

  return 0;

}

```

It converts decimal into binary but only in 32 bits. When I change it into 64 bits it doesn't work (it seems like it just doubles the result from 32 bits). At the same time it works fine with 8 or 4 bits etc. 
What am I doing wrong?

Answer: 
> 
> *It converts decimal into binary but only in 32 bits. When I change it into 64 bits it doesn't work (it seems like it just doubles the result from 32 bits).*
> 
> 
> 

The problem is here.

```
  int n, c, k;

  printf("Enter an integer\n");
  scanf("%d", &n);

```

`n` is an `int` which can be as small as 16 bits. It could be 64 bits, but it's probably 32 bits. When you try to enter a 64 bit number you'll get garbage.

```
#include <stdio.h>

int main() {
    int n;

    printf("sizeof(int) == %zu\n", sizeof(int));

    printf("Enter an integer\n");
    scanf("%d", &n);

    printf("n = %d\n", n);
}

$ ./test
sizeof(int) == 4
Enter an integer
12345678901
n = -539222987

```

Instead, you can use a `long long int` which has a minimum size of 64 bits or `int64_t` from [`stdint.h`](https://en.wikipedia.org/wiki/C_data_types#stdint.h) which is exactly 64 bits. I have a preference for using the explicit width types in code that requires a specific width to make it more obvious to the reader.

`long long int` uses `%lld` for `scanf` and `printf` while `int64_t` uses [macros from inttypes.h](https://en.wikipedia.org/wiki/C_data_types#Printf_and_scanf_format_specifiers). The code below takes advantage of C automatically concatenating constant strings; `"foo" "bar"` and `"foobar"` are equivalent.

```
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main() {
    int64_t n;

    printf("Enter an integer\n");

    scanf("%"SCNd64, &n);

    printf("n = %"PRId64"\n", n);
}

$ ./test
Enter an integer
12345678901
n = 12345678901

```
The problem is your n & k variables' data type. They are integer. Check your platform's data type size using sizeof(int). 

When you change to 64-bits, these variables can't hold 64-bit values.

HTH!