bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] bitwise operations


From: francky . leyn
Subject: [bug-gawk] bitwise operations
Date: Wed, 15 Feb 2012 10:40:21 +0100 (CET)

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?

 

Best regards,

 

Francky Leyn

 

www.Leyn.eu


reply via email to

[Prev in Thread] Current Thread [Next in Thread]