Skip to content

Instantly share code, notes, and snippets.

@mwleeds
Created September 25, 2019 01:10
Show Gist options
  • Save mwleeds/0437d23a6c28d47c1d6e3e8a77bf39b2 to your computer and use it in GitHub Desktop.
Save mwleeds/0437d23a6c28d47c1d6e3e8a77bf39b2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <glib.h>
static void
try_pack_and_unpack (gint64 number)
{
gint64 number_unpacked;
guint32 number_high;
guint32 number_low;
g_print ("Packing and unpacking %" G_GINT64_FORMAT "\n", number);
number_high = number >> 32;
number_low = number & 0xFFFFFFFF;
number_unpacked = number_high;
number_unpacked = (number_unpacked << 32) + number_low;
g_print ("Got %" G_GINT64_FORMAT "\n", number_unpacked);
}
int main (int argc, char **argv) {
try_pack_and_unpack (-1000);
try_pack_and_unpack (-1);
try_pack_and_unpack (0);
try_pack_and_unpack (1);
try_pack_and_unpack (1000);
try_pack_and_unpack (G_MAXUINT32);
try_pack_and_unpack ((gint64)G_MAXUINT32 + (gint64)1000);
try_pack_and_unpack (G_MAXINT64);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment