swab(1) - swap bytes #22

Closed
opened 2023-12-30 08:36:22 -07:00 by trinity · 3 comments
Owner

This pertains to #23 in that it fulfills functionality offered in POSIX by dd(1p), specifically dd conv=swab.

Usage: swab (-w [word size])

swab(1) swaps bytes in standard input to standard output. The default word size is 2, as in two-byte words with the latter half of the word (in this case, one byte) being output before the former half of the word.

$ swab
hello world
ehll oowlrd

If there are remaining bytes less than the word size they're left unconverted. Word sizes up to 16 (128 bits) will be supported.

$ echo hello world | swab -w 8
o wohellrld

The usefulness of such a tool is limited but this should be small and easy to make, and would fill in more POSIX functionality in a way that is simpler than POSIX.

This pertains to #23 in that it fulfills functionality offered in POSIX by dd(1p), specifically `dd conv=swab`. ``` Usage: swab (-w [word size]) ``` swab(1) swaps bytes in standard input to standard output. The default word size is 2, as in two-byte words with the latter half of the word (in this case, one byte) being output before the former half of the word. ```sh $ swab hello world ehll oowlrd ``` If there are remaining bytes less than the word size they're left unconverted. Word sizes up to 16 (128 bits) will be supported. ```sh $ echo hello world | swab -w 8 o wohellrld ``` The usefulness of such a tool is limited but this should be small and easy to make, and would fill in more POSIX functionality in a way that is simpler than POSIX.
trinity added the
enhancement
label 2023-12-30 09:00:34 -07:00
emma added the
help wanted
label 2023-12-30 14:39:42 -07:00
emma removed the
help wanted
label 2023-12-30 14:41:35 -07:00
emma changed title from swab(1) - swap bytes to `swab(1)` - swap bytes 2024-01-23 15:08:00 -07:00
Author
Owner

My current conundrum is that there are multiple useful types of byte reversal:

  • reversing bits in a byte
  • reversing bytes within a certain block size (e.g. "swabbing" - swapping bytes within a machine word - and the job of GNU tac(1), where all bytes in a file are reversed)
  • reversing bytes in blocks delimited by a certain byte sequence (e.g. GNU's rev(1), using '\n' or '\0')

The third should be relegated to a separate utility as it's higher level (plaintext) than endianness/bit order tomfoolery. Should the former two be separate utilities?

My current conundrum is that there are multiple useful types of byte reversal: - reversing bits in a byte - reversing bytes within a certain block size (e.g. "swabbing" - swapping bytes within a machine word - and the job of GNU tac(1), where all bytes in a file are reversed) - reversing bytes in blocks delimited by a certain byte sequence (e.g. GNU's rev(1), using '\n' or '\0') The third should be relegated to a separate utility as it's higher level (plaintext) than endianness/bit order tomfoolery. Should the former two be separate utilities?
emma added the
help wanted
label 2024-02-07 20:25:24 -07:00
Owner

Ah, I didn’t realize GNU had a utility called rev already. Will come up with another name.

Ah, I didn’t realize GNU had a utility called `rev` already. Will come up with another name.
Owner

On first consideration, I think it makes sense for all three to be separate utilities.

On first consideration, I think it makes sense for all three to be separate utilities.
trinity removed the
help wanted
label 2024-02-23 20:50:24 -07:00
trinity self-assigned this 2024-02-23 20:50:29 -07:00
emma closed this issue 2024-03-18 20:54:47 -06:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bonsai/harakit#22
No description provided.