Groups | Search | Server Info | Login | Register
Groups > comp.lang.awk > #10062
| From | Janis Papanagnou <janis_papanagnou+ng@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: Can I output a binary file from an AWK program? |
| Date | 2026-03-28 21:17 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <10q9d0f$th8s$1@dont-email.me> (permalink) |
| References | <10q99ai$ph7$1@news.muc.de> |
On 2026-03-28 20:14, Alan Mackenzie wrote:
> I think the Subject: line says it all. I have a text source file to
> convert into a binary output file. For example, I want to be able to
> output a 32-bit integer as a four byte little-endian binary integer.
This needs clarification. - Note that Awk has no 32 bit integer data
type. Usually you have text input, say "1234567", that is internally
stored in a numerically interpreted field.
> Can AWK do this? (It is supposed to by Turing complete, isn't it?)
Of course that can be done. You could read in the number and apply a
sequence of modulus and division operations on the read-in number; say
awk '{n=$0; printf "%c\n", n%256; n=int(n/256); ... }'
Or, in GNU Awk, you could extract the bytes by its bit-functions,
and(), rshift(), to extract the octet parts, then print them as a
character as above.
Janis
> [...]
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
Can I output a binary file from an AWK program? Alan Mackenzie <acm@muc.de> - 2026-03-28 19:14 +0000
Re: Can I output a binary file from an AWK program? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-28 21:17 +0100
Re: Can I output a binary file from an AWK program? Alan Mackenzie <acm@muc.de> - 2026-03-29 11:30 +0000
Re: Can I output a binary file from an AWK program? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-03-29 13:35 +0200
Re: Can I output a binary file from an AWK program? Kaz Kylheku <046-301-5902@kylheku.com> - 2026-03-29 23:45 +0000
Re: Can I output a binary file from an AWK program? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-29 17:07 -0700
Re: Can I output a binary file from an AWK program? Kaz Kylheku <046-301-5902@kylheku.com> - 2026-04-17 00:25 +0000
Re: Can I output a binary file from an AWK program? gazelle@shell.xmission.com (Kenny McCormack) - 2026-03-30 09:37 +0000
Re: Can I output a binary file from an AWK program? gazelle@shell.xmission.com (Kenny McCormack) - 2026-04-02 12:06 +0000
csiph-web