Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UibkA-00073z-E6 for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Jun 2013 02:40:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uibk9-0007g0-Uc for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Jun 2013 02:40:33 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uibk9-0007fk-1i for pgsql-bugs@postgresql.org; Sat, 01 Jun 2013 02:40:33 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uibk1-0007HJ-NR for pgsql-bugs@postgresql.org; Sat, 01 Jun 2013 02:40:32 +0000 Received: from [10.1.1.3] (60-234-150-59.bitstream.orcon.net.nz [60.234.150.59]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id r512cj9M022008 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 1 Jun 2013 14:38:46 +1200 Message-ID: <51A95EB5.9000104@archidevsys.co.nz> Date: Sat, 01 Jun 2013 14:38:45 +1200 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: John R Pierce CC: pgsql-bugs@postgresql.org Subject: Re: BUG #8191: Wrong bit conversion References: <11097.1370036031@sss.pgh.pa.us> <7A3A36FE51533446AAB1EA0F6069AC8C40A5B460@HEXBOSSSERVER.hexboss.local> <51A9406B.9040908@hogranch.com> <51A947D1.50205@archidevsys.co.nz> In-Reply-To: <51A947D1.50205@archidevsys.co.nz> Content-Type: multipart/alternative; boundary="------------020402080605040609090909" X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------020402080605040609090909 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 01/06/13 13:01, Gavin Flower wrote: > On 01/06/13 12:29, John R Pierce wrote: >> On 5/31/2013 4:29 PM, Gerald Luger wrote: >>> Shouldn't I expect all results to be 000...0001? >>> >>> Otherwise it would be >>> 1 != 1? >> >> SQL's BIT type is big endian, a hangover from its IBM mainframe >> heritage. >> >> >> >> >> > I don't think it has anything to do with byte sex (I know of 3 ways to > store integers in memory, and I suspect there are more !). > > Don't confuse how things are displayed with how they are stored in memory. > > Just that > 1 = two to the power of zero > so it seems logical to start numbering the bits to represent the > powers of 2. > > > Cheers, > Gavin Hmm... On second thoughts, it is strange that the first 2 examples affect bits on the left hand side! So now I think, that all 3 examples should logically be: RESULT: "0000000000000000000000000000000000000000000000000000000000000001", BUT, But, But... It appears for varchar padding is done on the right hand side, so maybe that is why the first 2examples are as they are (suggestive, not proof!). Cheers, Gavin --------------020402080605040609090909 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 01/06/13 13:01, Gavin Flower wrote:
On 01/06/13 12:29, John R Pierce wrote:
On 5/31/2013 4:29 PM, Gerald Luger wrote:
Shouldn't I expect all results to be 000...0001?

Otherwise it would be
1 != 1?

SQL's BIT type is big endian, a hangover from its IBM mainframe heritage.





I don't think it has anything to do with byte sex (I know of 3 ways to store integers in memory, and I suspect there are more !).

Don't confuse how things are displayed with how they are stored in memory.

Just that
    1 = two to the power of zero
so it seems logical to start numbering the bits to represent the powers of 2.


Cheers,
Gavin
Hmm...

On second thoughts, it is strange that the first 2 examples affect bits on the left hand side!

So now I think, that all 3 examples should logically be:

RESULT:
"0000000000000000000000000000000000000000000000000000000000000001",

BUT, But, But...

It appears for varchar padding is done on the right hand side, so maybe that is why the first 2 examples are as they are (suggestive, not proof!).


Cheers,
Gavin


--------------020402080605040609090909--