URGENT: Need help with AND binary operation in awk 
Author Message
 URGENT: Need help with AND binary operation in awk

Could anyone help me with the following:

I have a decimal number  nnnnnnnn in variable Var1
I need to convert this to it's binary equivalent store it in a variable
Var2.
Take Var2 and AND (binary AND) with another binary number 0000000 and
store the result in Var3.

An equivalently good one would be to replace the last x number of digits
in the binary variable Var2 with 0s.
I need to do this within awk.


Thank you



Thu, 29 Apr 2004 13:57:25 GMT  
 URGENT: Need help with AND binary operation in awk
Could anyone help me with the following:

I have a decimal number  nnnnnnnn in variable Var1
I need to convert this to it's binary equivalent store it in a variable
Var2.
Take Var2 and AND (binary AND) with another binary number 0000000 and
store the result in Var3.

An equivalently good one would be to replace the last x number of digits
in the binary variable Var2 with 0s.
I need to do this within awk.


Thank you



Thu, 29 Apr 2004 14:10:53 GMT  
 URGENT: Need help with AND binary operation in awk

Quote:

> Could anyone help me with the following:

> I have a decimal number  nnnnnnnn in variable Var1
> I need to convert this to it's binary equivalent store it in a variable
> Var2.
> Take Var2 and AND (binary AND) with another binary number 0000000 and
> store the result in Var3.

> An equivalently good one would be to replace the last x number of digits
> in the binary variable Var2 with 0s.
> I need to do this within awk.


> Thank you

gawk 3.1 has binary bit operators.

Before that, I did something like this:

function and(a, b    , res, p2, abit, bbit)
{
        res = 0; # the result
        p2 = 1; # power of 2 - the bit
        while ( (a > 0) || (b > 0) )
        {
                abit = a % 2;
                bbit = b % 2;
                a = (a-abit)/2
                b = (b-bbit)/2
                if ( abit && bbit )
                {
                        res = res + p2
                }
                p2 += p2
        }
        return res

Quote:
}

Grungy and slow, but (unless typos here) it worked.

Martin Cohen



Fri, 30 Apr 2004 14:36:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Need Help on awk!!!! **** Urgent ****

2. URGENT-help needed-URGENT

3. Urgent: need a tail recursive....decimal to binary source code

4. gnat.Direct.Operations. NEED HELP

5. Re-Post: Need Help with Invalid Operation Error

6. Help needed for window operations using Common Lisp under X-windows

7. urgent! need help with database bindings

8. 2nd post Urgent: Need help with FM2.9!

9. urgent help needed

10. clarion 5.5 urgent help needed

11. Help needed... URGENT

12. *URGENT* Help need with data export

 

 
Powered by phpBB® Forum Software