Return-Path: Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: (qmail 71523 invoked from network); 7 Jul 2010 12:27:11 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Jul 2010 12:27:11 -0000 Received: (qmail 10769 invoked by uid 500); 7 Jul 2010 12:27:10 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 10473 invoked by uid 500); 7 Jul 2010 12:27:06 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 10465 invoked by uid 99); 7 Jul 2010 12:27:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 12:27:05 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of juho.makinen@gmail.com designates 209.85.214.44 as permitted sender) Received: from [209.85.214.44] (HELO mail-bw0-f44.google.com) (209.85.214.44) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 12:26:57 +0000 Received: by bwz7 with SMTP id 7so4864716bwz.31 for ; Wed, 07 Jul 2010 05:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=AcF6wo3v2oJCaYasroEPbxjfyAErg5HnsZSzGASISiM=; b=h+tVZ6KmrjyZOk2qntwn6to20bOl7/Ecf5t7VtVySNPGqDJqVtNbR2qF6R9JVRFzz0 lMYicX9PcLDQlnFkt1ahg4spZYSyGPMCuWWDoWvRdE1B08nS+XdFWK5QQw78u2ulTLrK taxltCzem4rNAQj2HTmZ0zQSCU3uAOSfThcvE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ZAdLNg8LXP8F0rVKy6rF5WOPZ40iVFacJSR8Qvc/4Otjy6HehOWcNOoCyicQbUmvBP JTtVuSQI9v9UZXZACb/D1mUUdOZhliQJm6Xt+D4UYD3eTBFs1InH21fEAX1Wha4mme9I lgkVtHXE0a8jh0JrmDXW75jTrdcyQQqutljUw= MIME-Version: 1.0 Received: by 10.204.6.75 with SMTP id 11mr4141104bky.95.1278505597300; Wed, 07 Jul 2010 05:26:37 -0700 (PDT) Received: by 10.204.118.20 with HTTP; Wed, 7 Jul 2010 05:26:37 -0700 (PDT) In-Reply-To: References: Date: Wed, 7 Jul 2010 15:26:37 +0300 Message-ID: Subject: Re: a_long_is_exactly_8_bytes From: =?ISO-8859-1?Q?Juho_M=E4kinen?= To: user@cassandra.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Hello. I added that code and it works on our x86_64 bit Intel machine (just tested with your test.php). What environment are you using? I haven't tested the code on a 32bit machine and I believe that it will not work there. I should have propably added a note to the wiki that it wont work on 32bit environment. - Juho M=E4kinen On Wed, Jul 7, 2010 at 2:08 PM, john xie wrote: > > > http://wiki.apache.org/cassandra/FAQ#a_long_is_exactly_8_bytes > > /** > * Takes php integer and packs it to 64bit (8 bytes) long big end= ian > binary representation. > * @param $x integer > * @return string eight bytes long binary repersentation of the > integer in big endian order. > */ > public static function pack_longtype($x) { > return pack('C8', ($x >> 56) & 0xff, ($x >> 48) & 0xff, (= $x >>> 40) & 0xff, ($x >> 32) & 0xff, > ($x >> 24) & 0xff, ($x >> 16) & 0xff, ($x= >> > 8) & 0xff, $x & 0xff); > } > > /** > * Takes eight bytes long big endian binary representation of an > integer and unpacks it to a php integer. > * @param $x > * @return php integer > */ > public static function unpack_longtype($x) { > $a =3D unpack('C8', $x); > return ($a[1] << 56) + ($a[2] << 48) + ($a[3] << 40) + > ($a[4] << 32) + ($a[5] << 24) + ($a[6] << 16) + ($a[7] << 8) + $a[8]; > } > > test.php: > > =A0$input=3D1; > > =A0$output=3Dunpack_longtype(pack_longtype($input)); > > =A0=A0print "input=3D".$input." but output =3D ".$output."\n"; > > =A0$input=3D2; > > =A0$output=3Dunpack_longtype(pack_longtype($input)); > > =A0print "input=3D".$input." but output =3D ".$output."\n"; > > =A0 $input=3D3; > > =A0$output=3Dunpack_longtype(pack_longtype($input)); > > =A0print "input=3D".$input." but output =3D ".$output."\n"; > > but in log file: > > input=3D1 but output =3D 2 > > input=3D2 but output =3D 4 > > input=3D3 but output =3D 6 > > >