Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"You must have an IQ of at least half a million." -- Popeye


devel / comp.lang.awk / Re: Bitwise xor of two bytes does not work as I expected

SubjectAuthor
* Bitwise xor of two bytes does not work as I expectedMohsen Owzar
+- Re: Bitwise xor of two bytes does not work as I expectedMack The Knife
+* Re: Bitwise xor of two bytes does not work as I expectedJanis Papanagnou
|+- Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
|`* Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
| `* Re: Bitwise xor of two bytes does not work as I expectedJanis Papanagnou
|  +- Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
|  `* Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
|   +- Re: Bitwise xor of two bytes does not work as I expectedJanis Papanagnou
|   `* Re: Bitwise xor of two bytes does not work as I expectedKenny McCormack
|    `* Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
|     `* Re: Bitwise xor of two bytes does not work as I expectedKpop 2GM
|      `* Re: Bitwise xor of two bytes does not work as I expectedMohsen Owzar
|       `* Re: Bitwise xor of two bytes does not work as I expectedKenny McCormack
|        +- Re: Bitwise xor of two bytes does not work as I expectedKpop 2GM
|        `* Re: Bitwise xor of two bytes does not work as I expectedKpop 2GM
|         +- Re: Bitwise xor of two bytes does not work as I expectedKenny McCormack
|         `- Re: Bitwise xor of two bytes does not work as I expectedJanis Papanagnou
`* Re: Bitwise xor of two bytes does not work as I expectedKeith Thompson
 `- Re: Bitwise xor of two bytes does not work as I expectedEd Morton

1
Bitwise xor of two bytes does not work as I expected

<93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1269&group=comp.lang.awk#1269

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:6214:1cce:b0:470:85e2:dc3e with SMTP id g14-20020a0562141cce00b0047085e2dc3emr10687228qvd.52.1657867590678;
Thu, 14 Jul 2022 23:46:30 -0700 (PDT)
X-Received: by 2002:a25:b9c3:0:b0:668:a418:13c with SMTP id
y3-20020a25b9c3000000b00668a418013cmr12148081ybj.498.1657867590361; Thu, 14
Jul 2022 23:46:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Thu, 14 Jul 2022 23:46:30 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
Subject: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Fri, 15 Jul 2022 06:46:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2165
 by: Mohsen Owzar - Fri, 15 Jul 2022 06:46 UTC

Hi guys,
I have to check some data in the Labview programming for the RS 232 interface.
In that protocol I must build the checksum of the data to be sent.

For example, for the given data:
03, 58, 43 and 30:
I have to take from left to right two data (03 and 58) and build the xor of them as shown below
0000 0011
0101 1000
=======0101 1011
Or
03 xor 58  5B
This result should be taken with the next data (43) to build the Xor and the result of them should be xored with the last data (30) as shown below:
0101 1011  5B
0100 0011  43
==============0001 1000  18

0001 1000  18
0011 0000  30
==============0010 1000  28

So, to check this with AWK, I've written this one liner, but this seems not to work:
awk 'BEGIN {a = ARGV[1]; DELETE ARGV[1]; a = ARGV[2]; DELETE ARGV[2]; print (xor(a, b))}' 1011 1100
1100
Instead of giving me
0101 1011 = 5B
It gives only
1100 = C
Why? Where I'm doing something wrong?

Re: Bitwise xor of two bytes does not work as I expected

<tar5k9$1gsa$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1270&group=comp.lang.awk#1270

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!TCpKYLtZ4Zv96uwS8Sp8LQ.user.46.165.242.75.POSTED!not-for-mail
From: mack@the-knife.org (Mack The Knife)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 07:39:53 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <tar5k9$1gsa$1@gioia.aioe.org>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="50058"; posting-host="TCpKYLtZ4Zv96uwS8Sp8LQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Originator: aharon@skeeve.com (Aharon Robbins)
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
X-Notice: Filtered by postfilter v. 0.9.2
 by: Mack The Knife - Fri, 15 Jul 2022 07:39 UTC

In article <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>,
Mohsen Owzar <mohsen.owzar@gmail.com> wrote:
>Hi guys,
>I have to check some data in the Labview programming for the RS 232 interface.
>In that protocol I must build the checksum of the data to be sent.
>
>For example, for the given data:
>03, 58, 43 and 30:
>I have to take from left to right two data (03 and 58) and build the xor
>of them as shown below
>0000 0011
>0101 1000
>========
>0101 1011
>Or
>03 xor 58  5B
>This result should be taken with the next data (43) to build the Xor and
>the result of them should be xored with the last data (30) as shown
>below:
>0101 1011  5B
>0100 0011  43
>===============
>0001 1000  18
>
>0001 1000  18
>0011 0000  30
>===============
>0010 1000  28
>
>So, to check this with AWK, I've written this one liner, but this seems
>not to work:
>awk 'BEGIN {a = ARGV[1]; DELETE ARGV[1]; a = ARGV[2]; DELETE ARGV[2];
>print (xor(a, b))}' 1011 1100
>1100
>Instead of giving me
>0101 1011 = 5B
>It gives only
>1100 = C
>Why? Where I'm doing something wrong?

Gawk converts values as decimal. You want to use hex.
Something like

gawk 'BEGIN {
a = strtonum(ARGV[1])
b = strtonum(ARGV[2])
printf("%#x\n", xor(a, b))
}' 0x03 0x58

Mack The Knife

Re: Bitwise xor of two bytes does not work as I expected

<tarcmq$3142e$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1271&group=comp.lang.awk#1271

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 11:40:41 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <tarcmq$3142e$1@dont-email.me>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 15 Jul 2022 09:40:42 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="eec24a7f599a89ef166dc2f2df8102f9";
logging-data="3182670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MIy2CW/tCk3z+xNrxgPIo"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:fxurF6khBrB/Yv742NGJO2YYf/U=
In-Reply-To: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 15 Jul 2022 09:40 UTC

On 15.07.2022 08:46, Mohsen Owzar wrote:
> Hi guys,
> I have to check some data in the Labview programming for the RS 232 interface.
> In that protocol I must build the checksum of the data to be sent.
>
> For example, for the given data:
> 03, 58, 43 and 30:
> I have to take from left to right two data (03 and 58) and build the xor of them as shown below
> 0000 0011
> 0101 1000
> ========
> 0101 1011
> Or
> 03 xor 58  5B
> This result should be taken with the next data (43) to build the Xor and the result of them should be xored with the last data (30) as shown below:
> 0101 1011  5B
> 0100 0011  43
> ===============
> 0001 1000  18
>
> 0001 1000  18
> 0011 0000  30
> ===============
> 0010 1000  28
>
> So, to check this with AWK, I've written this one liner, but this seems not to work:
> awk 'BEGIN {a = ARGV[1]; DELETE ARGV[1]; a = ARGV[2]; DELETE ARGV[2]; print (xor(a, b))}' 1011 1100
> 1100
> Instead of giving me
> 0101 1011 = 5B
> It gives only
> 1100 = C
> Why? Where I'm doing something wrong?

Probably in many places. First, please tell us what awk version you are
using that supports binary operations; is that GNU awk? Does this awk
support binary string literals (like 1011)? (You seem to xor the binary
representation of the *decimal* numbers 1011 and 1100 here.) Does this
awk support DELETE with all caps? (Using 'delete' is anyway unnecessary
here.) Then the question whether overwriting 'a' (a second time) is
intentional? (b=... is probably meant.)

PS: In what environment are you working? Doing that (here [OT]) in a
shell, ksh, might be simpler that using awk for binary base numbers.

Janis

Re: Bitwise xor of two bytes does not work as I expected

<11166dc5-fc92-4d2f-95bc-393f5751243dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1272&group=comp.lang.awk#1272

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:6214:246f:b0:473:5145:d906 with SMTP id im15-20020a056214246f00b004735145d906mr11354943qvb.126.1657881869637;
Fri, 15 Jul 2022 03:44:29 -0700 (PDT)
X-Received: by 2002:a05:6902:1083:b0:66f:193f:edf with SMTP id
v3-20020a056902108300b0066f193f0edfmr12881653ybu.281.1657881869336; Fri, 15
Jul 2022 03:44:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 15 Jul 2022 03:44:29 -0700 (PDT)
In-Reply-To: <tarcmq$3142e$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com> <tarcmq$3142e$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <11166dc5-fc92-4d2f-95bc-393f5751243dn@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Fri, 15 Jul 2022 10:44:29 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 31
 by: Mohsen Owzar - Fri, 15 Jul 2022 10:44 UTC

Janis Papanagnou schrieb am Freitag, 15. Juli 2022 um 11:40:44 UTC+2:

> Probably in many places. First, please tell us what awk version you are
> using that supports binary operations; is that GNU awk? Does this awk
> support binary string literals (like 1011)? (You seem to xor the binary
> representation of the *decimal* numbers 1011 and 1100 here.) Does this
> awk support DELETE with all caps? (Using 'delete' is anyway unnecessary
> here.) Then the question whether overwriting 'a' (a second time) is
> intentional? (b=... is probably meant.)
>
> PS: In what environment are you working? Doing that (here [OT]) in a
> shell, ksh, might be simpler that using awk for binary base numbers.
>
> Janis
Hi Janis,

Excuse me for unprecise question.
I'm using GAWK under CYGWIN.
The Version of GAWK is:
m.owzar@ /cygdrive/c/cygwin/home/m.owzar/BinMo
$> gawk --version
GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1)
Copyright (C) 1989, 1991-2021 Free Software Foundation.

In the manual "A User’s Guide for GNU Awk, Edition 4, June, 2011" on page 167, 168
Under "9.1.6 Bit-Manipula:ion Functions" I found:
xor(v1, v2) Return the bitwise XOR of the values provided by v1 and v2.

Re: Bitwise xor of two bytes does not work as I expected

<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1273&group=comp.lang.awk#1273

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ad4:5765:0:b0:473:20e:746c with SMTP id r5-20020ad45765000000b00473020e746cmr11339941qvx.128.1657882347724;
Fri, 15 Jul 2022 03:52:27 -0700 (PDT)
X-Received: by 2002:a25:b9c3:0:b0:668:a418:13c with SMTP id
y3-20020a25b9c3000000b00668a418013cmr12949017ybj.498.1657882347488; Fri, 15
Jul 2022 03:52:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 15 Jul 2022 03:52:27 -0700 (PDT)
In-Reply-To: <tarcmq$3142e$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com> <tarcmq$3142e$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Fri, 15 Jul 2022 10:52:27 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 6
 by: Mohsen Owzar - Fri, 15 Jul 2022 10:52 UTC

@ Mack the Knife
Thanks a lot for your correction of the code.
It works well.
I haven't used awk for a long tine and forgot to convert the read argument into a number.
Stupid mistake

Regards Mohsen

Re: Bitwise xor of two bytes does not work as I expected

<tarm8j$323c7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1274&group=comp.lang.awk#1274

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 14:23:46 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <tarm8j$323c7$1@dont-email.me>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<tarcmq$3142e$1@dont-email.me>
<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 15 Jul 2022 12:23:47 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="eec24a7f599a89ef166dc2f2df8102f9";
logging-data="3214727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18K+VVRY5tVP8+AZpBPgwJP"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:I+OvddINTa1PdALoP7TqEwCQ7v0=
In-Reply-To: <a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
 by: Janis Papanagnou - Fri, 15 Jul 2022 12:23 UTC

On 15.07.2022 12:52, Mohsen Owzar wrote:
> @ Mack the Knife
> Thanks a lot for your correction of the code.
> It works well.

And it works with binary literals as you requested in your sample?
Can you show us the GNU awk program that works with such binary
arguments, please?

Janis

> I haven't used awk for a long tine and forgot to convert the read argument into a number.
> Stupid mistake
>
> Regards Mohsen
>

Re: Bitwise xor of two bytes does not work as I expected

<b2dfda4e-9c9f-4884-98db-58449465ee1an@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1275&group=comp.lang.awk#1275

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ad4:57ae:0:b0:473:8181:b484 with SMTP id g14-20020ad457ae000000b004738181b484mr11786852qvx.82.1657889439022;
Fri, 15 Jul 2022 05:50:39 -0700 (PDT)
X-Received: by 2002:a25:b9c3:0:b0:668:a418:13c with SMTP id
y3-20020a25b9c3000000b00668a418013cmr13464118ybj.498.1657889438680; Fri, 15
Jul 2022 05:50:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 15 Jul 2022 05:50:38 -0700 (PDT)
In-Reply-To: <tarm8j$323c7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<tarcmq$3142e$1@dont-email.me> <a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
<tarm8j$323c7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b2dfda4e-9c9f-4884-98db-58449465ee1an@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Fri, 15 Jul 2022 12:50:39 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 11
 by: Mohsen Owzar - Fri, 15 Jul 2022 12:50 UTC

Janis Papanagnou schrieb am Freitag, 15. Juli 2022 um 14:23:49 UTC+2:
> And it works with binary literals as you requested in your sample?
> Can you show us the GNU awk program that works with such binary
> arguments, please?

No, unfortunately not.
It was a mistake.
You were right with your assumption.
Thanks a lot for your hint.

Regards
Mohsen

Re: Bitwise xor of two bytes does not work as I expected

<dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1276&group=comp.lang.awk#1276

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ae9:e702:0:b0:6b5:9c37:8b23 with SMTP id m2-20020ae9e702000000b006b59c378b23mr9752395qka.511.1657891295939;
Fri, 15 Jul 2022 06:21:35 -0700 (PDT)
X-Received: by 2002:a05:6902:4d0:b0:66e:4fef:cc3f with SMTP id
v16-20020a05690204d000b0066e4fefcc3fmr13133716ybs.20.1657891295711; Fri, 15
Jul 2022 06:21:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 15 Jul 2022 06:21:35 -0700 (PDT)
In-Reply-To: <tarm8j$323c7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<tarcmq$3142e$1@dont-email.me> <a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
<tarm8j$323c7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Fri, 15 Jul 2022 13:21:35 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 50
 by: Mohsen Owzar - Fri, 15 Jul 2022 13:21 UTC

Now to calculate all the checksums of the sent data, I have put two set of data as an example in a file "data.txt" as below:
--------------------------------------------
7F # Begin pattern
03 # Length of the coming data
58
43
30
28
06 # End pattern
7F # Begin pattern
07 # Length of the coming data
58
53
30
56
34
30
30
5E # This checksum should be calculated
06 # End pattern
--------------------------------------------
7F and 06 are the begin and end pattern of each data, which must be ignored.
My program should ignore 7F and xor 03 and 58 which has the result 28.
Then should take this result (28) and xor it with the next data (43) to get the result 18.
This result (18) after xoring with the last data (30) should give the value 28 like the next value after 30.
--------------------------------------------
And I have written this AWK code two calculate and print the checksum values of the two data sets.
--------------------------------------------
#! /usr/bin/awk -f
# Calculate_Checksum_for_Serial_Interface.awk
# 2022_07_15
#####################################################
$1 == "7F", $1 == "06" {
CheckSum = 0
if ($1 != "7F" && $1 != "06") {
Data[++N] = $0
printf "%s\n", Data[N]
CheckSum = xor(CheckSum, strtonum(Data[N]))
printf "CheckSum = %X\n", CheckSum
}
}

But somehow, I cannot get it managed.
It prints something else than I described above.
I haven't written for long time AWK scripts more.

Do you have any idea?

Regards
Mohsen

Re: Bitwise xor of two bytes does not work as I expected

<tas2kr$33ctc$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1277&group=comp.lang.awk#1277

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 17:55:04 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <tas2kr$33ctc$1@dont-email.me>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<tarcmq$3142e$1@dont-email.me>
<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com>
<tarm8j$323c7$1@dont-email.me>
<dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 15 Jul 2022 15:55:07 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="eec24a7f599a89ef166dc2f2df8102f9";
logging-data="3257260"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5oXP7x5hzgVumTPtf7dQv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:dkTTVlTqbZBG365Rwkub2Lt9nZw=
In-Reply-To: <dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>
 by: Janis Papanagnou - Fri, 15 Jul 2022 15:55 UTC

On 15.07.2022 15:21, Mohsen Owzar wrote:
> CheckSum = xor(CheckSum, strtonum(Data[N]))

>
> But somehow, I cannot get it managed.
> It prints something else than I described above.

Could it be that you need: strtonum("0x"Data[N])

Janis

> I haven't written for long time AWK scripts more.
>
> Do you have any idea?
>
> Regards
> Mohsen
>

Re: Bitwise xor of two bytes does not work as I expected

<87wnce49dx.fsf@nosuchdomain.example.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1278&group=comp.lang.awk#1278

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 09:40:26 -0700
Organization: None to speak of
Lines: 16
Message-ID: <87wnce49dx.fsf@nosuchdomain.example.com>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="2152a851c60bd7ce1985f4f42a8f6873";
logging-data="3263465"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+G3mbzkpZOgbmYkgSQrCmU"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:IGU03klUCiIc/1IY8XHdnXAegYk=
sha1:PaJ3M+qnL/dyFo+pk82pbrxPMkk=
 by: Keith Thompson - Fri, 15 Jul 2022 16:40 UTC

Mohsen Owzar <mohsen.owzar@gmail.com> writes:
[...]
> So, to check this with AWK, I've written this one liner, but this seems not to work:
> awk 'BEGIN {a = ARGV[1]; DELETE ARGV[1]; a = ARGV[2]; DELETE ARGV[2]; print (xor(a, b))}' 1011 1100
> 1100
[...]

Awk is case-sensitive. There's nothing called "DELETE". Apparently
"DELETE ARGV[1]" does nothing (I haven't taken the time to figure out
why it doesn't produce an error message). The behavior is the same
when I replace "DELETE" by a random identifier.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Bitwise xor of two bytes does not work as I expected

<tash7l$34rk6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1279&group=comp.lang.awk#1279

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 15:04:05 -0500
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <tash7l$34rk6$1@dont-email.me>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<87wnce49dx.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 15 Jul 2022 20:04:06 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="fea731f3f2a3bfe706f05f9247a4505c";
logging-data="3305094"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ZA2tRQ8FRsVQIznC/ZEfm"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.10.0
Cancel-Lock: sha1:3pjzHQFJShwaIyAowxx3t+O4MBQ=
X-Antivirus-Status: Clean
In-Reply-To: <87wnce49dx.fsf@nosuchdomain.example.com>
Content-Language: en-US
X-Antivirus: Avast (VPS 220715-4, 7/15/2022), Outbound message
 by: Ed Morton - Fri, 15 Jul 2022 20:04 UTC

On 7/15/2022 11:40 AM, Keith Thompson wrote:
> Mohsen Owzar <mohsen.owzar@gmail.com> writes:
> [...]
>> So, to check this with AWK, I've written this one liner, but this seems not to work:
>> awk 'BEGIN {a = ARGV[1]; DELETE ARGV[1]; a = ARGV[2]; DELETE ARGV[2]; print (xor(a, b))}' 1011 1100
>> 1100
> [...]
>
> Awk is case-sensitive. There's nothing called "DELETE". Apparently
> "DELETE ARGV[1]" does nothing (I haven't taken the time to figure out
> why it doesn't produce an error message). The behavior is the same
> when I replace "DELETE" by a random identifier.
>

DELETE ARGV[1] concatenates the value of the unset variable DELETE with
the value of ARGV[1] then does nothing with the resulting string.
Perfectly valid, just useless in this context.

Ed.

Re: Bitwise xor of two bytes does not work as I expected

<tasrdb$2tddg$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1280&group=comp.lang.awk#1280

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Fri, 15 Jul 2022 22:57:47 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tasrdb$2tddg$1@news.xmission.com>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com> <a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com> <tarm8j$323c7$1@dont-email.me> <dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>
Injection-Date: Fri, 15 Jul 2022 22:57:47 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3061168"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 15 Jul 2022 22:57 UTC

In article <dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com>,
Mohsen Owzar <mohsen.owzar@gmail.com> wrote:
>Now to calculate all the checksums of the sent data, I have put two set of data
>as an example in a file "data.txt" as below:
>--------------------------------------------

I think this what you're after:

Data file:
7F # Begin pattern
03 # Length of the coming data
58
43
30
28
06 # End pattern
7F # Begin pattern
07 # Length of the coming data
58
53
30
56
34
30
30
5E # This checksum should be calculated
06 # End pattern

Program:
# Run as: gawk -f thisfile datafile
# Calculate_Checksum_for_Serial_Interface.awk
# 2022_07_15
#####################################################
$1 == "7F" { flag = 1 ; CheckSum = 0 ; next }
$1 == "06" { flag = 0 ; next }
flag {
printf "%#X\t", val = strtonum("0x" $1)
CheckSum = xor(CheckSum, val)
printf "CheckSum = %#X\n", CheckSum
}

Note: I didn't bother to actually verify the numerical accuracy of the
results, because I don't really understand the underlying goal of the
exercise.

--
If you don't have faith, it's because you are reading the Bible with an
honest, truthful, real-answer seeking heart.

- Rick C Hodgin -

Re: Bitwise xor of two bytes does not work as I expected

<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1281&group=comp.lang.awk#1281

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:12cd:b0:6b5:d8da:7ce7 with SMTP id e13-20020a05620a12cd00b006b5d8da7ce7mr1473277qkl.579.1657947121392;
Fri, 15 Jul 2022 21:52:01 -0700 (PDT)
X-Received: by 2002:a05:6902:140d:b0:66e:ba97:77f6 with SMTP id
z13-20020a056902140d00b0066eba9777f6mr17927295ybu.38.1657947121172; Fri, 15
Jul 2022 21:52:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 15 Jul 2022 21:52:00 -0700 (PDT)
In-Reply-To: <tasrdb$2tddg$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com> <tarm8j$323c7$1@dont-email.me>
<dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com> <tasrdb$2tddg$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Sat, 16 Jul 2022 04:52:01 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3547
 by: Mohsen Owzar - Sat, 16 Jul 2022 04:52 UTC

Kenny McCormack schrieb am Samstag, 16. Juli 2022 um 00:57:49 UTC+2:

> Note: I didn't bother to actually verify the numerical accuracy of the
> results, because I don't really understand the underlying goal of the
> exercise.

Hi all,
@ Keith and Ed
You are right.
This DELETE command does nothing as you explained.
It was my fault after having not written programs in AWK for a long time.

@ Kenny
Yes, it is. It was my intention I wanted to achieve.
I have rewritten my code and ran it on the whole data.
It has generated correct values for all datasets.

And the answer to your question about the sense of my data protocol, if you are interested in is as the following:
I have an IO-Device which controls some LEDs to turn them on or off and a camera to take some pictures of the LED spots on a screen.
The firmware in the IO-Device in the micro controller is already given by the firmware programmer.
For RS 232 interface we have to use VISA and send (write) data onto device and get back (read) the answer from the device.
These string-ins and string-outs for a command like “GetVersion” (version of the firmware in the micro controller) looks like the following:

String-in
7F 03 58 43 30 28 06
SYNC LEN X C 0 RLC EOF

String-out
7F 07 58 53 30 56 34 30 30 5E 06
SYNC LEN X S 0 V 4 0 0 RLC EOF

7F (Sync) and 06 (End Of Frame) are the boundary of each data set.
LEN is the length of the data to be sent and RLC is the checksum of the sent or read data.
It means that
28 is the checksum of four values (03, 58, 43 and 30) for string-in and
5E is the checksum of 8 values (07, 58, 53, 30, 56, 34, 30, 30)

And your corrected version of my program does this perfectly.
The only thing for getting the firmware version I have to send “XC0” as command surrounded with prefix 7F and LEN and suffix RLC and 06.
The received data from the device has the same boundary elements (prefix 7F and LEN respect. RLC and 06) with the data in between (XS0V400).
XS0 stands for operation OK and V400 is the version of the firmware.

With best regards to all of you
Mohsen

Re: Bitwise xor of two bytes does not work as I expected

<68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1301&group=comp.lang.awk#1301

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:290d:b0:6b5:cecc:1cab with SMTP id m13-20020a05620a290d00b006b5cecc1cabmr15778666qkp.465.1658920496648;
Wed, 27 Jul 2022 04:14:56 -0700 (PDT)
X-Received: by 2002:a81:638b:0:b0:31e:23d5:7529 with SMTP id
x133-20020a81638b000000b0031e23d57529mr18582466ywb.263.1658920496491; Wed, 27
Jul 2022 04:14:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 27 Jul 2022 04:14:56 -0700 (PDT)
In-Reply-To: <20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:0:0:0:3c3;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:0:0:0:3c3
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com> <tarm8j$323c7$1@dont-email.me>
<dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com> <tasrdb$2tddg$1@news.xmission.com>
<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Wed, 27 Jul 2022 11:14:56 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1665
 by: Kpop 2GM - Wed, 27 Jul 2022 11:14 UTC

if you wanna avoid have to call strtonum( ) all the time, use the -n flag at startup :

gawk -n -b -e '$++NF = sprintf("0x %.8X", xor( +$1 , +$2 ))' OFS='\n' <<< ' 0x88776655 0x311DD993 '

0x 88776655
0x 311DD993
0x B96ABFC6

Re: Bitwise xor of two bytes does not work as I expected

<7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1302&group=comp.lang.awk#1302

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ac8:5f12:0:b0:31f:36e2:39bb with SMTP id x18-20020ac85f12000000b0031f36e239bbmr13948391qta.375.1658943146620;
Wed, 27 Jul 2022 10:32:26 -0700 (PDT)
X-Received: by 2002:a0d:ea85:0:b0:31f:4a57:24e8 with SMTP id
t127-20020a0dea85000000b0031f4a5724e8mr7492152ywe.20.1658943146329; Wed, 27
Jul 2022 10:32:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 27 Jul 2022 10:32:26 -0700 (PDT)
In-Reply-To: <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=31.164.81.19; posting-account=BtTavwoAAACMi3AFrA3U-JBERbxGUGhD
NNTP-Posting-Host: 31.164.81.19
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<a44188c9-3acd-4597-8258-f1832a75fb85n@googlegroups.com> <tarm8j$323c7$1@dont-email.me>
<dc99d701-8822-4a0c-9c9c-7fbde1b4e97dn@googlegroups.com> <tasrdb$2tddg$1@news.xmission.com>
<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com> <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: mohsen.owzar@gmail.com (Mohsen Owzar)
Injection-Date: Wed, 27 Jul 2022 17:32:26 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1809
 by: Mohsen Owzar - Wed, 27 Jul 2022 17:32 UTC

jason....@gmail.com schrieb am Mittwoch, 27. Juli 2022 um 13:14:57 UTC+2:
> if you wanna avoid have to call strtonum( ) all the time, use the -n flag at startup :
>
> gawk -n -b -e '$++NF = sprintf("0x %.8X", xor( +$1 , +$2 ))' OFS='\n' <<< ' 0x88776655 0x311DD993 '
>
> 0x 88776655
> 0x 311DD993
> 0x B96ABFC6
Thanks a lot

Best regards
Mohsen

Re: Bitwise xor of two bytes does not work as I expected

<tbru64$3d92l$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1303&group=comp.lang.awk#1303

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Wed, 27 Jul 2022 17:55:16 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tbru64$3d92l$1@news.xmission.com>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com> <20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com> <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com> <7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com>
Injection-Date: Wed, 27 Jul 2022 17:55:16 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3581013"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 27 Jul 2022 17:55 UTC

In article <7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com>,
Mohsen Owzar <mohsen.owzar@gmail.com> wrote:
>jason....@gmail.com schrieb am Mittwoch, 27. Juli 2022 um 13:14:57 UTC+2:
>> if you wanna avoid have to call strtonum( ) all the time, use the -n flag at startup :
>>
>> gawk -n -b -e '$++NF = sprintf("0x %.8X", xor( +$1 , +$2 ))' OFS='\n' <<< '
>0x88776655 0x311DD993 '
>>
>> 0x 88776655
>> 0x 311DD993
>> 0x B96ABFC6
>Thanks a lot
>
>Best regards
>Mohsen

Note that this depends on the bash-ism of <<<
(I don't know [or care] if any other shells implement it)

I think the -n (non-decimal-data) option was sort of only partially
implemented, and then got abandoned/deprecated by the developers.
The fact that it only works on input data, not on strings contained in the
program, is kind of a deal-breaker for me.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Reaganomics

Re: Bitwise xor of two bytes does not work as I expected

<ddfb8239-8a1c-47a3-a25f-f2d3769752f6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1304&group=comp.lang.awk#1304

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ae9:e702:0:b0:6b5:9c37:8b23 with SMTP id m2-20020ae9e702000000b006b59c378b23mr18502385qka.511.1658954368050;
Wed, 27 Jul 2022 13:39:28 -0700 (PDT)
X-Received: by 2002:a5b:7c6:0:b0:670:6ba6:d046 with SMTP id
t6-20020a5b07c6000000b006706ba6d046mr18624199ybq.140.1658954367864; Wed, 27
Jul 2022 13:39:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 27 Jul 2022 13:39:27 -0700 (PDT)
In-Reply-To: <tbru64$3d92l$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:0:0:0:3c3;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:0:0:0:3c3
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com> <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
<7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com> <tbru64$3d92l$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ddfb8239-8a1c-47a3-a25f-f2d3769752f6n@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Wed, 27 Jul 2022 20:39:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6473
 by: Kpop 2GM - Wed, 27 Jul 2022 20:39 UTC

he -n (non-decimal-data) option was sort of only partially
> implemented, and then got abandoned/deprecated by the developers.
> The fact that it only works on input data, not on strings contained in the
> program, is kind of a deal-breaker for me.

0xABCDEF1234567
3022415481488743
3022415481488743

0xFFFFFBBBB1111
4503598482002193
4503598482002193

# gawk profile, created Wed Jul 27 16:23:06 2022
# BEGIN rule(s)

gawk -d- -p- -n -b -e '
BEGIN {

1 OFS = ORS
1 _ = "0xABCDEF1234567"
1 print "", _, +_, strtonum(_), ""
1 __ = 0xFFFFFBBBB1111
1 print "", __, +__, strtonum(__), ""
}

_: "0xABCDEF1234567"
__: 4503598482002193

You don't need to contemplate about tradeoffs - you have simultaneous access to both.
(note that first test case in a string,
2nd is a source code constant),

The only reason Arnold tried warning people to stay away from it is because leading zeros gets octal-decoded instead, so as long as you know exactly what you're doing, it's a great feature that's one of the most underrated.

From everything I've seen so far, it works just like s2n. Using just this tiny bit of syntax (next section), you can even directly decode arbitrarily large hex input without any function calls

gawk -nMbe '$++NF = +$_'

<<< $'0xFFFFFBBBB11FFFFFBBBB1111FFFFFBBBB11FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111111\n0xABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF128888888888888888888834567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567'

0xFFFFFBBBB11FFFFFBBBB1111FFFFFBBBB11FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111FFFFFBBBB1111111

792410481646616505940015000922854762744740671457867320743901473455933528744978850062048762862883942445525635692307798461905632480501012011096400210064677766678999906102075532691817396150908877637911699936390025554616004702352634076014122288896340204968302468430833810028641892689528530396772919229032922120676191493949322801021779981817073411777529139765810172013836465217011970968434212005035841316398621556889190978730637998199560973318985274390342067388654875762277420079317807823056337881279321136369340204985282842983017647888357332662597023472432476204933821245498817882242982792948216196147421085112855567884413125558670444123899473660999012831952983059532300226833

0xABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF128888888888888888888834567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567ABCDEF1234567

147756656133133375059351666795447984278054882222533236595909293890685589866885373840348521196663726563576447415924545810526238707724997382127366903652083960255538003615196549414054013680043219084492803632778613732247026252292747211855616100560906066384901785190067087361163419350457120581150307988552198430060501148970441659114216572552701453237232433617072788364057940404735915402922707276024780803259994084711965740498550069678887837257707432535593118909370394246796395560873743559698062561227554788546397543

One more thing - standard mode gives you nothing for negative hex, but -n mode handles it just fine :

gawk -be 'BEGIN { OFS=ORS=RS RS } ($++NF = strtonum($_))^_' <<< $'-0xBBBBBCCCCCCCD'

-0xBBBBBCCCCCCCD
0

gawk -nbe 'BEGIN { OFS=ORS=RS RS } ($++NF = strtonum($_))^_' <<< $'-0xBBBBBCCCCCCCD'

-0xBBBBBCCCCCCCD
-3302640013069517

Re: Bitwise xor of two bytes does not work as I expected

<40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1305&group=comp.lang.awk#1305

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:17a4:b0:6b6:7ef7:643 with SMTP id ay36-20020a05620a17a400b006b67ef70643mr1598737qkb.759.1658954485362;
Wed, 27 Jul 2022 13:41:25 -0700 (PDT)
X-Received: by 2002:a05:6902:1143:b0:66e:eb08:4c23 with SMTP id
p3-20020a056902114300b0066eeb084c23mr19181167ybu.570.1658954485190; Wed, 27
Jul 2022 13:41:25 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 27 Jul 2022 13:41:24 -0700 (PDT)
In-Reply-To: <tbru64$3d92l$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:0:0:0:3c3;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:0:0:0:3c3
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com> <68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
<7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com> <tbru64$3d92l$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>
Subject: Re: Bitwise xor of two bytes does not work as I expected
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Wed, 27 Jul 2022 20:41:25 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1690
 by: Kpop 2GM - Wed, 27 Jul 2022 20:41 UTC

> Note that this depends on the bash-ism of <<<
> (I don't know [or care] if any other shells implement it)

I use that only cuz i'm too lazy to be thumping the POSIX-Bible. Feel free to change that to command line variable assignment or echo or printf or whatever you think would make Richard Stallman happy.

Re: Bitwise xor of two bytes does not work as I expected

<tbs9ev$3dej0$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1306&group=comp.lang.awk#1306

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Wed, 27 Jul 2022 21:07:43 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tbs9ev$3dej0$1@news.xmission.com>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com> <7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com> <tbru64$3d92l$1@news.xmission.com> <40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>
Injection-Date: Wed, 27 Jul 2022 21:07:43 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3586656"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 27 Jul 2022 21:07 UTC

In article <40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>,
Kpop 2GM <jason.cy.kwan@gmail.com> wrote:
>
>> Note that this depends on the bash-ism of <<<
>> (I don't know [or care] if any other shells implement it)
>
>I use that only cuz i'm too lazy to be thumping the POSIX-Bible. Feel
>free to change that to command line variable assignment or echo or
>printf or whatever you think would make Richard Stallman happy.

w/e

Anyway, I'm the last person you'll meet that would get hung up on any sort
of "standards compliance". If you examine my posting history, that will be
borne out. In any case, I use bash exclusively in my shell coding, and am
of the opinion that using any other shell is silly.

That said, I only included the comment quoted above because it relates to
the subsequent comment about "non-decimal-data" not working in program
code. Note that I did not bother to read your recent long post - it didn't
seem worth the trouble to try to parse it.

--
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof.

- John Kenneth Galbraith -

Re: Bitwise xor of two bytes does not work as I expected

<tbsaq7$2kp5f$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1307&group=comp.lang.awk#1307

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: Bitwise xor of two bytes does not work as I expected
Date: Wed, 27 Jul 2022 23:30:46 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <tbsaq7$2kp5f$1@dont-email.me>
References: <93c55d4c-2b3c-42eb-a378-06ad6ec72d55n@googlegroups.com>
<20b11f3a-f4cb-4647-afad-ea328532310dn@googlegroups.com>
<68bae254-5102-4823-a81b-f62a875421b8n@googlegroups.com>
<7ad10c4b-4f50-434c-8c15-09d17b54a438n@googlegroups.com>
<tbru64$3d92l$1@news.xmission.com>
<40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Jul 2022 21:30:47 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="5104198a0fb7e554810e3495d98fa3c8";
logging-data="2778287"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CI0lmIyzpsDY774IX19j6"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:c4/FhmnrihJAN7RN+CZg17hY6L0=
In-Reply-To: <40753535-d20a-4e26-af81-4684c32ca9c9n@googlegroups.com>
 by: Janis Papanagnou - Wed, 27 Jul 2022 21:30 UTC

On 27.07.2022 22:41, Kpop 2GM wrote:
>
>> Note that this depends on the bash-ism of <<< (I don't know [or
>> care] if any other shells implement it)
>
> I use that only cuz i'm too lazy to be thumping the POSIX-Bible. Feel
> free to change that to command line variable assignment or echo or
> printf or whatever you think would make Richard Stallman happy.

Don't worry, the prominent powerful shells (ksh, zsh, bash) all support
that here-string redirection. Users of plain POSIX shells or worse will
know how to work around it; here-documents were long existing for that
purpose with only little overhead.

Janis

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor