![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to access values of awk/nawk variables outside the awk/nawk block? | saniya | Shell Programming and Scripting | 5 | 05-13-2008 07:37 AM |
| nawk/ksh help | DeltaX | Shell Programming and Scripting | 0 | 03-06-2008 03:54 PM |
| NAWK question | DeltaX | Shell Programming and Scripting | 6 | 02-01-2008 06:34 PM |
| nawk -v to awk | kamel.seg | Shell Programming and Scripting | 2 | 12-18-2007 07:30 AM |
| nawk | whatisthis | Shell Programming and Scripting | 3 | 09-29-2004 01:44 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
nawk question
I am trying to write the following c code in nawk:
while ((ch = getc (fp)) != EOF) { total_bytes++; checksum = (checksum >> 1) + ((checksum & 1) << 15); checksum += ch; checksum &= 0xffff; /* Keep it within bounds. */ } I appreciate your help |
|
||||
|
My nawk man pages do not have and "&=" or ">> <<" shift left or shift right operators.
nawk apparently does not support that. You can fake >> and << with division by 2 and multiplication by two. I don't know a way to fake the "and" operation without writing some very tricky code. You are doing 32 bit operations. That means "anding" 32 values. Try cksum or write your own C code. That makes more sense. Maybe one of our ultimo awkers have done this solidly, but it looks like a nightmare waiting to happen to me. |
|
|||||
|
the most recent 'gawk' supports bitwise ops: and, or, xor, compl, lshift and rshift
here's something found seaching comp.lang.awk: Code:
function awkand(a,b, k,r) {
k = 1
r = 0
a = int(a + 0.5) # round to nearest integer
b = int(b + 0.5)
while ( a + b ) {
if ( a%2 && b%2 ) r += k
a = int(a / 2)
b = int(b / 2)
k *= 2
}
return r
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|