Last active
August 9, 2026 09:52
-
-
Save digizeph/c711745ba7b949ea506349db87340eda to your computer and use it in GitHub Desktop.
ntohll: a macro for network to host byte conversion for 64 bits numbers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| Version 2, December 2004 | |
| Copyright (C) 2017 Mingwei Zhang <mingwei@mwzhang.com> | |
| Everyone is permitted to copy and distribute verbatim or modified | |
| copies of this license document, and changing it is allowed as long | |
| as the name is changed. | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
| 0. You just DO WHAT THE FUCK YOU WANT TO. | |
| */ | |
| #include <stdio.h> | |
| #include <ntsid.h> | |
| #define htonll(x) ((((long long)htonl(x))<<32) + (htonl((x)>>32))) | |
| int main() { | |
| long long a = 0x8877665544332211; | |
| long long b = ((long long)htonl(a))<<32; | |
| long long c = htonl(a>>32); | |
| long long d = (((long long)htonl(a))<<32) + (htonl(a>>32)); | |
| printf("a - 0x%llx\n", a); | |
| printf("b - 0x%llx\n", b); | |
| printf("c - 0x%llx\n", c); | |
| printf("b+c - 0x%llx\n", b+c); | |
| printf("d - 0x%llx\n", d); | |
| printf("macro - 0x%llx\n", htonll(a)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment