From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 15 08:33:48 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 02112106566C for ; Wed, 15 Aug 2012 08:33:48 +0000 (UTC) (envelope-from dgre090@gmail.com) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id ADD598FC12 for ; Wed, 15 Aug 2012 08:33:47 +0000 (UTC) Received: by vbmv11 with SMTP id v11so1664741vbm.13 for ; Wed, 15 Aug 2012 01:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=9+95uJ/TERfLWFfCawdo9S28dzZuGaM/MkSWpM9XeoY=; b=s1Ss/2apCMkSsgCBtIdhlBXhBM/ihSd2lBivDX0ZqoZD2Q5/NxJfzAOYYItx0YdLZ/ 2ueP3bqbt8xHJJq9XeZ0Spl0y+vQefr/jiXzFmCiSWFa+gA1qEg3rgvwoj5iFOS8y6NS DW4CDlZRP9PnAjC/hVloRsQo92MR92h76eE89xF99mBwCnK/KK11BZRZY1zYHE0JY0by XrOewrmi4VUk+17O4t5ZbYFygP2oY8qFWnbkJ+wI6ThlyWMmTDSwImMNUMQd8cNZCEfo l3k6gKout6SdlcDaSIMyON6X0ieXmsftJaaIgwzmidRKvahaGULYtzRm5X8LMo2u8o5z Voeg== MIME-Version: 1.0 Received: by 10.220.149.130 with SMTP id t2mr12414065vcv.8.1345019626753; Wed, 15 Aug 2012 01:33:46 -0700 (PDT) Received: by 10.58.132.143 with HTTP; Wed, 15 Aug 2012 01:33:46 -0700 (PDT) Date: Wed, 15 Aug 2012 10:33:46 +0200 Message-ID: From: Daniel Grech To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Unsigned Integer Encoding X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Aug 2012 08:33:48 -0000 Hi, I have what is probably a really elementary question but I can't seem to figure it out. In the following snippet of code, why is it that a and b do not have the same value in the end ? : #define uint32_t unsigned int #define uint16_t unsigned short #define uint8_t unsigned char #define uint64_t unsigned long long int main () { uint32_t a = 0x01020304; /* This prints 01020304 */ printf ("a = %0X \n",a); uint32_t * b; uint8_t bytes [] = {0x01,0x02,0x03,0x04}; b = (uint32_t *) bytes; /* This prints 04030201 */ printf ("b= %0X \n", *b); return 1; } Im asking this as I am currently encoding a protocol in which i receive data as a sequence of bytes. Casting for example 4 bytes from this stream leaves me with the situation in variable b, while the situation I am looking to accomplish is the one in A (i.e. the bytes are not encoded in reverse form). Thanks in advance for your help. Regards, Daniel