Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal to hex for int64 in c

Tags:

c

Why this code does not work ?

#include <iostream>
#include <cstdio>
int main() {
  printf("%X", 1327644190303473294);
}

I am getting o/p 5f264e8e

but expected o/p is 126cbd5b5f264e8e as given by below php script

<?php
  echo dechex(1327644190303473294);
?>
like image 592
Vivek Goel Avatar asked Nov 24 '25 09:11

Vivek Goel


1 Answers

format '%X' expects type 'unsigned int', but argument 2 has type 'long int'

#include <stdio.h>

int main(void) {
    printf("%lX",1327644190303473294);
    return 0;
}

outputs

126CBD5B5F264E8E
like image 68
Fredrik Pihl Avatar answered Nov 27 '25 02:11

Fredrik Pihl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!