Skip to content

Instantly share code, notes, and snippets.

@lisp3r
Created January 8, 2024 15:27
Show Gist options
  • Save lisp3r/8a1c4d1f8a70e7914aa86f9308f5be02 to your computer and use it in GitHub Desktop.
Save lisp3r/8a1c4d1f8a70e7914aa86f9308f5be02 to your computer and use it in GitHub Desktop.
Convert int64_t to char* string
// 0x616a2f656d6f682f -> aj/emoh/ -> /home/ja
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
void int64_to_char(char mesg[], int64_t num) {
for(int i = 0; i < 8; i++)
mesg[i] = num >> (8-1-i)*8;
}
char *strrev(char *str) {
char *p1, *p2;
if (! str || ! *str)
return str;
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2){
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
return str;
}
int main(int argc, char** argv) {
int64_t x64_constant = 0x616a2f656d6f682f;
char *dest_str = (char*)malloc(8);
int64_to_char(dest_str, x64_constant);
printf("%s", strrev(dest_str));
free(dest_str);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment