[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] bitwise operations
From: |
Davide Brini |
Subject: |
Re: [bug-gawk] bitwise operations |
Date: |
Wed, 15 Feb 2012 12:34:19 +0100 |
On Wed, 15 Feb 2012 10:40:21 +0100 (CET), address@hidden wrote:
>
> Hello,
>
> I have read
> http://www.gnu.org/software/gawk/manual/html_node/Bitwise-Functions.html
>
> I need something similar as in the example given there.
> However, I do it in a differrent way.
> However, I not very succesfull: the code gives wrong results.
> I'm wondering why. The code:
>
> #! /bin/sh
> gawk '
> BEGIN {
> number = 2
> print "number = "number
>
>
> bit_0 = ((number && 1) == 0 ? 0 : 1)
> bit_1 = ((number && 2) == 0 ? 0 : 1)
> bit_2 = (number && 4 ? 1 : 0)
> bit_3 = (number && 8 ? 1 : 0)
>
>
> print "bit 0 = "bit_0
> print "bit 1 = "bit_1
> print "bit 2 = "bit_2
> print "bit 3 = "bit_3
> }
> '
>
> The obtained values for bit_0 ... bit_3 are
> always wrong, regardless of number.
> Why is this not working correctly?
The "&&" operator is a logical AND, not a bitwise operator.
--
D.