Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Linux: The OS people choose without $200,000,000 of persuasion. -- Mike Coleman


devel / comp.lang.awk / Re: number to binary / binary to number

SubjectAuthor
* number to binary / binary to numberDigi
+* Re: number to binary / binary to numberJanis Papanagnou
|`- Re: number to binary / binary to numberJanis Papanagnou
`* Re: number to binary / binary to numberKenny McCormack
 `* Re: number to binary / binary to numberDigi
  +- Re: number to binary / binary to numberKpop 2GM
  `- Re: number to binary / binary to numberKpop 2GM

1
number to binary / binary to number

<613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:6214:508a:b0:440:f824:3d55 with SMTP id kk10-20020a056214508a00b00440f8243d55mr2488406qvb.26.1650113346905;
Sat, 16 Apr 2022 05:49:06 -0700 (PDT)
X-Received: by 2002:a81:5b08:0:b0:2ef:512e:e5be with SMTP id
p8-20020a815b08000000b002ef512ee5bemr2797943ywb.215.1650113346783; Sat, 16
Apr 2022 05:49:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.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: Sat, 16 Apr 2022 05:49:06 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.69.210; posting-account=jE5YhQoAAAA6NRkuvHlc3hbR50dRS9Kb
NNTP-Posting-Host: 82.131.69.210
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
Subject: number to binary / binary to number
From: cosmogen@gmail.com (Digi)
Injection-Date: Sat, 16 Apr 2022 12:49:06 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 39
 by: Digi - Sat, 16 Apr 2022 12:49 UTC

what is "heavy" in gawk?

i may provide example of what i meaning:

if you're parsing some structures, for example or generate an graphic file or cutting audio file or any more - you will need to work with the numbers in it's binary forms:

thus "0123" is the 0x33323130 (hex: 30 31 32 33)

so to convert from number to it's binary form i will need something like:

BEGIN{
for ( i = 0; i < 256; i++ )
ASC[ CHR[ i ] = sprintf( "%.c", i ) ] = i

n = numtobin32( 0x1234567 )
print dump( n )

}

func numtobin32( n ) {

return CHR[ and( 0xFF, n ) ] \
CHR[ and( 0xFF, rshift( n, 8 ) ) ] \
CHR[ and( 0xFF, rshift( n, 16 ) ) ] \
CHR[ and( 0xFF, rshift( n, 24 ) ) ] }

the opposite conversion is looking even worse:

func bintonum( t ,a,r,A ) {

split( t, A, "" )
r = 0
while( ++a in A )
r = lshift( r, 8 ) + ASC[ A[ a ] ]
return r + 0 }

the paradox is in that both conversions above transform one four bytes of data into another - exactly the same four bytes ...

Re: number to binary / binary to number

<t3ef0i$tav$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: number to binary / binary to number
Date: Sat, 16 Apr 2022 15:06:26 +0200
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <t3ef0i$tav$1@dont-email.me>
References: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Apr 2022 13:06:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b1f540aa0d2984dcaed169276763f508";
logging-data="30047"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tu8A03+fbWEbPIOswQF4w"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:lH4BhVzyL+1tA7xuIMKVszoQApA=
In-Reply-To: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
 by: Janis Papanagnou - Sat, 16 Apr 2022 13:06 UTC

On 16.04.2022 14:49, Digi wrote:
> what is "heavy" in gawk?
>
> i may provide example of what i meaning:
>
> if you're parsing some structures, for example or generate an graphic file or cutting audio file or any more - you will need to work with the numbers in it's binary forms:
>
>
> thus "0123" is the 0x33323130 (hex: 30 31 32 33)
>
> so to convert from number to it's binary form i will need something like:
>
>
> BEGIN{
> for ( i = 0; i < 256; i++ )
> ASC[ CHR[ i ] = sprintf( "%.c", i ) ] = i
>
> n = numtobin32( 0x1234567 )
>
> print dump( n )
>
> }
>
> func numtobin32( n ) {
>
> return CHR[ and( 0xFF, n ) ] \
> CHR[ and( 0xFF, rshift( n, 8 ) ) ] \
> CHR[ and( 0xFF, rshift( n, 16 ) ) ] \
> CHR[ and( 0xFF, rshift( n, 24 ) ) ] }
>
> the opposite conversion is looking even worse:
>
> func bintonum( t ,a,r,A ) {
>
> split( t, A, "" )
> r = 0
> while( ++a in A )
> r = lshift( r, 8 ) + ASC[ A[ a ] ]
> return r + 0 }
>
> the paradox is in that both conversions above transform one four bytes of data into another - exactly the same four bytes ...
>

You haven't provided any question or statement in your post. Nonetheless
I'd say that the answer to your thoughts is @include "binary_ops", where
the library is what you may want to provide.

Janis

Re: number to binary / binary to number

<t3efs2$4u0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: number to binary / binary to number
Date: Sat, 16 Apr 2022 15:21:06 +0200
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <t3efs2$4u0$1@dont-email.me>
References: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
<t3ef0i$tav$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 16 Apr 2022 13:21:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b1f540aa0d2984dcaed169276763f508";
logging-data="5056"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iFDJea8x3k7ZmMzI+a5Mo"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:5FqdWvwR/WMP6WLa43qxkI4+iVE=
In-Reply-To: <t3ef0i$tav$1@dont-email.me>
 by: Janis Papanagnou - Sat, 16 Apr 2022 13:21 UTC

On 16.04.2022 15:06, Janis Papanagnou wrote:
> On 16.04.2022 14:49, Digi wrote:
>> what is "heavy" in gawk?
>>
>> i may provide example of what i meaning:
>>
>> if you're parsing some structures, for example or generate an graphic file or cutting audio file or any more - you will need to work with the numbers in it's binary forms:
>>
>>
>> thus "0123" is the 0x33323130 (hex: 30 31 32 33)
>>
>> so to convert from number to it's binary form i will need something like:
>>
>>
>> BEGIN{
>> for ( i = 0; i < 256; i++ )
>> ASC[ CHR[ i ] = sprintf( "%.c", i ) ] = i
>>
[...]
>
> You haven't provided any question or statement in your post. Nonetheless
> I'd say that the answer to your thoughts is @include "binary_ops", where
> the library is what you may want to provide.

I saw that there's an 'ordchar' extension in gawk's extension directory
which may help you reduce own implementation efforts.

>
> Janis
>

Re: number to binary / binary to number

<t3ehed$30idd$1@news.xmission.com>

  copy mid

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

  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: number to binary / binary to number
Date: Sat, 16 Apr 2022 13:47:57 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <t3ehed$30idd$1@news.xmission.com>
References: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
Injection-Date: Sat, 16 Apr 2022 13:47:57 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3164589"; 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 - Sat, 16 Apr 2022 13:47 UTC

In article <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>,
Digi <cosmogen@gmail.com> wrote:
>what is "heavy" in gawk?
>
>i may provide example of what i meaning:
>
>if you're parsing some structures, for example or generate an graphic file or
>cutting audio file or any more - you will need to work with the numbers in it's
>binary forms:

Yes, this is a weakness in the AWK model. The reason we program in AWK in
the first place is so that we don't have to worry about this stuff - i.e.,
the underlying representations of numbers and strings. We can just program
as if numbers and strings are native (and basically interchangeable) types.

But, every so often, we have a need to go below the surface. To get at the
underlying bits and bytes. In my case, this is usually when I want to
access some underlying Unix/Linux functionality that GAWK doesn't currently
provide. For example, I recently decided to re-implement the "touch"
utility in GAWK. To do so, I had to be able to access (one of the many)
"utime" function(s) from GAWK. As it happens, accessing the function
itself was easy (once you have already built functionality to access
arbitrary system calls from GAWK, as I have done), but the hard part (hard
only because it had not already been done) was creating functionality to
convert a GAWK number into the underlying binary representation needed to
pass to the system call.

This was all written up in a recent thread here on this newsgroup (q.v.).
The gist of it was that this function will do the work:

function encode(n, i,s) {
s = sprintf("%c",n)
for (i=1; i<4; i++)
s = s sprintf("%c",rshift(n,i*8))
return s
}

But it is not exactly a thing of beauty.

Overall, I think the best advice I can give is that if you think you're
going to be doing this in any ongoing scale, you will probably end up
writing an extension library (in C) to do most of the nitty gritty stuff.

--
Men rarely (if ever) manage to dream up a God superior to themselves.
Most Gods have the manners and morals of a spoiled child.

Re: number to binary / binary to number

<a1839637-f257-4baf-bebd-2920984f7807n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ac8:6ce:0:b0:2f0:29dd:bbc5 with SMTP id j14-20020ac806ce000000b002f029ddbbc5mr4404948qth.216.1650197000442;
Sun, 17 Apr 2022 05:03:20 -0700 (PDT)
X-Received: by 2002:a25:e691:0:b0:641:80fe:7364 with SMTP id
d139-20020a25e691000000b0064180fe7364mr5805021ybh.593.1650197000242; Sun, 17
Apr 2022 05:03:20 -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: Sun, 17 Apr 2022 05:03:19 -0700 (PDT)
In-Reply-To: <t3ehed$30idd$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.69.210; posting-account=jE5YhQoAAAA6NRkuvHlc3hbR50dRS9Kb
NNTP-Posting-Host: 82.131.69.210
References: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com> <t3ehed$30idd$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a1839637-f257-4baf-bebd-2920984f7807n@googlegroups.com>
Subject: Re: number to binary / binary to number
From: cosmogen@gmail.com (Digi)
Injection-Date: Sun, 17 Apr 2022 12:03:20 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 32
 by: Digi - Sun, 17 Apr 2022 12:03 UTC

Jaanis:

"I saw that there's an 'ordchar' extension in gawk's extension directory
which may help you reduce own implementation efforts."
yeah, i just providing (commonly) an examples in it's best(performance) case.
and i want just discuss about some themes in gawk.

i hear that this is good place for this. isn't ? is there another places? )

Kenny:

"Yes, this is a weakness in the AWK model."

but i hear here from somebody from gawk team that gawk is positions itself as: perfectly suited for "pure file parsing".
it is still so, but this is strange that the best language have that's kind of weakness.

it's looks like such kind of things should be compensated by the two new dynamic extensions:

n = bintonum( t )

and like:

t = numtobin( n, bytewide)

but this is also not the perfect solution because of at least one reason: dynamic extensions is also requiring file infrastructure that is hard on the remote machines.

however it is looks like i should start to do that by myself. i mean writing dynamic extensions ... it's time =)

regards
D

Re: number to binary / binary to number

<e4c71557-3e9c-40f3-97b2-1bfc852429c2n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:622a:24f:b0:2e1:d658:a595 with SMTP id c15-20020a05622a024f00b002e1d658a595mr3043634qtx.657.1650633467761;
Fri, 22 Apr 2022 06:17:47 -0700 (PDT)
X-Received: by 2002:a25:50c5:0:b0:645:77f1:40df with SMTP id
e188-20020a2550c5000000b0064577f140dfmr4287149ybb.525.1650633467500; Fri, 22
Apr 2022 06:17:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!border1.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, 22 Apr 2022 06:17:47 -0700 (PDT)
In-Reply-To: <a1839637-f257-4baf-bebd-2920984f7807n@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: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
<t3ehed$30idd$1@news.xmission.com> <a1839637-f257-4baf-bebd-2920984f7807n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e4c71557-3e9c-40f3-97b2-1bfc852429c2n@googlegroups.com>
Subject: Re: number to binary / binary to number
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Fri, 22 Apr 2022 13:17:47 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 139
 by: Kpop 2GM - Fri, 22 Apr 2022 13:17 UTC

@Digi : If you want a num-to-bin to handle it all, even when using gawk unicode mode, you can try this :

The exact code can print out any arbitrary 4-byte combination in mawk-1, mawk-2, macOS nawk, gawk byte mode, and gawk unicode mode.

It also has auto awk-variant detection in order to make necessary behavior adjustments, such as mawk-1 not printing large hex or negative hex, nawk not printing negative hex, mawk-2 not having auto-comma feature, and ensuring gawk-unicode-mode doesn't interpret the values as unicode code points.

gawk -e '
function encode(_,__,___) {
return \
sprintf("%c%c%c%c",
(__<__)*((_%=(___=(__^=__^=__+=__^=__<__)*__*__)*__)+\
(_=(_+___*__)%(___*__)))+___+(_/=___),
___+(_*=__),
___+(_*=__),
___+(_*=__))
} BEGIN {
___=2^2^5;
__["1701734259"]
__["3891792015"]
__["2405365991"]
__[ sprintf("%.f", 3^32-4^7) ]
__["-444025027"]=\
__["3850942269"]=-1;

PROCINFO["sorted_in"] = "@val_num_asc";

for(_ in __) {
printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47"\
)"22.f | 0x %16.8x )> = [[ %-.4s ]] \n",
_,+"0x1" ? ((_%___)+___)%___ : _, encode(_))
} }'

32-bit usgned <( -444,025,027 | 0x ffffffffe588b73d )> = [[ 刷= ]]
32-bit usgned <( 3,850,942,269 | 0x e588b73d )> = [[ 刷= ]]
32-bit usgned <( 1,701,734,259 | 0x 656e6773 )> = [[ engs ]]
32-bit usgned <( 1,853,020,188,835,457 | 0x 6954fe21dfe81 )> = [[ ??? ]]
32-bit usgned <( 2,405,365,991 | 0x 8f5ef8e7 )> = [[ ?^?? ]]
32-bit usgned <( 3,891,792,015 | 0x e7f8088f )> = [[ ?? ]]

% echo; gawk -b -e 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*((_%=(___=(__^=__^=__+=__^=__<__)*__*__)*__)+(_=(_+___*__)%(___*__)))+___+(_/=___),(_*=__)+___,___+(_*=__),___+int(_*__)) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %-.4s ]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

32-bit usgned <( -444,025,027 | 0x ffffffffe588b73d )> = [[ 刷= ]]
32-bit usgned <( 3,850,942,269 | 0x e588b73d )> = [[ 刷= ]]
32-bit usgned <( 1,701,734,259 | 0x 656e6773 )> = [[ engs ]]
32-bit usgned <( 1,853,020,188,835,457 | 0x 6954fe21dfe81 )> = [[ ??? ]]
32-bit usgned <( 2,405,365,991 | 0x 8f5ef8e7 )> = [[ ?^?? ]]
32-bit usgned <( 3,891,792,015 | 0x e7f8088f )> = [[ ?? ]]

% echo; mawk 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*((_%=(___=(__^=__^=__+=__^=__<__)*__*__)*__)+(_=(_+___*__)%(___*__)))+___+(_/=___),(_*=__)+___,___+(_*=__),___+int(_*__)) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %-.4s ]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

32-bit usgned <( 1,701,734,259 | 0x 656e6773 )> = [[ engs ]]
32-bit usgned <( 1,853,020,188,835,457 | 0x e21dfe81 )> = [[ ??? ]]
32-bit usgned <( 2,405,365,991 | 0x 8f5ef8e7 )> = [[ ?^?? ]]
32-bit usgned <( 3,891,792,015 | 0x e7f8088f )> = [[ ?? ]]
32-bit usgned <( 3,850,942,269 | 0x e588b73d )> = [[ 刷? ]]
32-bit usgned <( -444,025,027 | 0x e588b73d )> = [[ 刷? ]]

% echo; mawk2 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*((_%=(___=(__^=__^=__+=__^=__<__)*__*__)*__)+(_=(_+___*__)%(___*__)))+___+(_/=___),(_*=__)+___,___+(_*=__),___+int(_*__)) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %-.4s ]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

32-bit usgned <( 3891792015 | 0x e7f8088f )> = [[ ?? ]]
32-bit usgned <( 3850942269 | 0x e588b73d )> = [[ 刷= ]]
32-bit usgned <( 1701734259 | 0x 656e6773 )> = [[ engs ]]
32-bit usgned <( 1853020188835457 | 0x 6954fe21dfe81 )> = [[ ??? ]]
32-bit usgned <( 2405365991 | 0x 8f5ef8e7 )> = [[ ?^?? ]]
32-bit usgned <( -444025027 | 0x ffffffffe588b73d )> = [[ 刷= ]]

% echo; nawk 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*((_%=(___=(__^=__^=__+=__^=__<__)*__*__)*__)+(_=(_+___*__)%(___*__)))+___+(_/=___),(_*=__)+___,___+(_*=__),___+int(_*__)) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %-.4s ]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

32-bit usgned <( 3,850,942,269 | 0x e588b73d )> = [[ 刷? ]]
32-bit usgned <( 3,891,792,015 | 0x e7f8088f )> = [[ ?? ]]
32-bit usgned <( 1,701,734,259 | 0x 656e6773 )> = [[ engs ]]
32-bit usgned <( -444,025,027 | 0x e588b73d )> = [[ 刷? ]]
32-bit usgned <( 2,405,365,991 | 0x 8f5ef8e7 )> = [[ ?^?? ]]
32-bit usgned <( 1,853,020,188,835,457 | 0x e21dfe81 )> = [[ ??? ]]

Re: number to binary / binary to number

<5abf52ac-256e-4906-bbbe-5cde50de14f9n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:ac8:65c5:0:b0:2f1:e813:6078 with SMTP id t5-20020ac865c5000000b002f1e8136078mr3216892qto.187.1650634738855;
Fri, 22 Apr 2022 06:38:58 -0700 (PDT)
X-Received: by 2002:a81:c93:0:b0:2f4:e780:d157 with SMTP id
141-20020a810c93000000b002f4e780d157mr3492086ywm.379.1650634738625; Fri, 22
Apr 2022 06:38:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Fri, 22 Apr 2022 06:38:58 -0700 (PDT)
In-Reply-To: <a1839637-f257-4baf-bebd-2920984f7807n@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: <613c5e48-d8f9-4df6-8c3e-f78462669035n@googlegroups.com>
<t3ehed$30idd$1@news.xmission.com> <a1839637-f257-4baf-bebd-2920984f7807n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5abf52ac-256e-4906-bbbe-5cde50de14f9n@googlegroups.com>
Subject: Re: number to binary / binary to number
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Fri, 22 Apr 2022 13:38:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Kpop 2GM - Fri, 22 Apr 2022 13:38 UTC

[[ REPOSTING due to minor mawk-1/nawk bug found ]]

@Digi : If you want a num-to-bin to handle it all, even when using gawk unicode mode, you can try this :

The exact code can print out any arbitrary 4-byte combination in mawk-1.3.4, mawk-1.9.9.6, gawk 5.1.1 byte mode, gawk 5.1.1 unicode mode, and macOS nawk.

It also has auto awk-variant detection in order to make necessary behavior adjustments, such as mawk-1 not printing large hex or negative hex, nawk not printing negative hex, mawk-2 not having auto-comma feature, and ensuring gawk-unicode-mode doesn't interpret the values as multi-byte unicode code points. (remove the leading dots - they're only for formatting purposes on newsgroup)

... gawk -e '
.....function encode(_,__,___) {
.....return \
.....sprintf("%c%c%c%c",(__<__)*((_%=___=(__^=__^=__+=__=__==__)\
.........*__*__*__)+(_=int(_+___)%___))+int(_/=___/=__)%__+___,
........................................... int(_*=__)%__+___,
...........................................int(_*=__)%__+___,
.........................................int(_*__)%__+___)
... } BEGIN {
.........___=2^2^5; __["1701734259"]__["3891792015"]
.........__["2405365991"]__[sprintf("%.f",3^32-4^7)]
.........__["-444025027"]=__["3850942269"]=-1

.........PROCINFO["sorted_in"]="@val_num_asc"

.........for(_ in __) {
.............printf(" \t 32-bit usgned <( %"(\
...................("\333\222")~"[^\333\222]"?"":"\47"\
................... )"22.f | 0x %16.8x )> = [[ %.4s\t]] \n",
..................._, +"0x1" ? ((_%___)+___)%___ : _, encode(_))
.........}
.....}'

.........32-bit usgned <(.......... -444,025,027 | 0x ffffffffe588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........3,850,942,269 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........1,701,734,259 | 0x........ 656e6773 )> = [[ engs ]]
.........32-bit usgned <(..1,853,020,188,835,457 | 0x....6954fe21dfe81 )> = [[ ??? ]]
.........32-bit usgned <(..........2,405,365,991 | 0x........ 8f5ef8e7 )> = [[ ?^?? ]]
.........32-bit usgned <(..........3,891,792,015 | 0x........ e7f8088f )> = [[ ?? ]]

% echo; mawk 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*( (_%=___=(__^=__^=__+=__=__==__)*__*__*__)+(_=int(_+___)%___))+int(_/=___/=__)%__+___, int(_*=__)%__+___,int(_*=__)%__+___,int(_*__)%__+___) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %.4s\t]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

.........32-bit usgned <(..........1,701,734,259 | 0x........ 656e6773 )> = [[ engs ]]
.........32-bit usgned <(..1,853,020,188,835,457 | 0x........ e21dfe81 )> = [[ ??? ]]
.........32-bit usgned <(..........2,405,365,991 | 0x........ 8f5ef8e7 )> = [[ ?^?? ]]
.........32-bit usgned <(..........3,891,792,015 | 0x........ e7f8088f )> = [[ ?? ]]
.........32-bit usgned <(..........3,850,942,269 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(.......... -444,025,027 | 0x........ e588b73d )> = [[ 刷= ]]

% echo; mawk2 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*( (_%=___=(__^=__^=__+=__=__==__)*__*__*__)+(_=int(_+___)%___))+int(_/=___/=__)%__+___, int(_*=__)%__+___,int(_*=__)%__+___,int(_*__)%__+___) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %.4s\t]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

.........32-bit usgned <(............ 3891792015 | 0x........ e7f8088f )> = [[ ?? ]]
.........32-bit usgned <(............ 3850942269 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(............ 1701734259 | 0x........ 656e6773 )> = [[ engs ]]
.........32-bit usgned <(...... 1853020188835457 | 0x....6954fe21dfe81 )> = [[ ??? ]]
.........32-bit usgned <(............ 2405365991 | 0x........ 8f5ef8e7 )> = [[ ?^?? ]]
.........32-bit usgned <(............ -444025027 | 0x ffffffffe588b73d )> = [[ 刷= ]]

% echo; nawk 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*( (_%=___=(__^=__^=__+=__=__==__)*__*__*__)+(_=int(_+___)%___))+int(_/=___/=__)%__+___, int(_*=__)%__+___,int(_*=__)%__+___,int(_*__)%__+___) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %.4s\t]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

.........32-bit usgned <(..........3,850,942,269 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........3,891,792,015 | 0x........ e7f8088f )> = [[ ?? ]]
.........32-bit usgned <(..........1,701,734,259 | 0x........ 656e6773 )> = [[ engs ]]
.........32-bit usgned <(.......... -444,025,027 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........2,405,365,991 | 0x........ 8f5ef8e7 )> = [[ ?^?? ]]
.........32-bit usgned <(..1,853,020,188,835,457 | 0x........ e21dfe81 )> = [[ ??? ]]

% echo; gawk -b -e 'function encode(_,__,___) { return sprintf("%c%c%c%c",(__<__)*( (_%=___=(__^=__^=__+=__=__==__)*__*__*__)+(_=int(_+___)%___))+int(_/=___/=__)%__+___, int(_*=__)%__+___,int(_*=__)%__+___,int(_*__)%__+___) } BEGIN {___=2^2^5; __["1701734259"]__["3891792015"]__["2405365991"]__[sprintf("%.f",3^32-4^7)];__["-444025027"]=__["3850942269"]=-1; PROCINFO["sorted_in"]="@val_num_asc"; for(_ in __) { printf(" \t 32-bit usgned <( %"(("\333\222")~"[^\333\222]"?"":"\47")"22.f | 0x %16.8x )> = [[ %.4s\t]] \n",_,+"0x1" ? ((_%___)+___)%___ : _, encode(_)) } }'

.........32-bit usgned <(.......... -444,025,027 | 0x ffffffffe588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........3,850,942,269 | 0x........ e588b73d )> = [[ 刷= ]]
.........32-bit usgned <(..........1,701,734,259 | 0x........ 656e6773 )> = [[ engs ]]
.........32-bit usgned <(..1,853,020,188,835,457 | 0x....6954fe21dfe81 )> = [[ ??? ]]
.........32-bit usgned <(..........2,405,365,991 | 0x........ 8f5ef8e7 )> = [[ ?^?? ]]
.........32-bit usgned <(..........3,891,792,015 | 0x........ e7f8088f )> = [[ ?? ]]

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor