Skip to content
Discussion options

You must be logged in to vote

Sure. Here is a solution using ksh only and thus avoiding external programs like wc.

ksh93 displayes the results of a binary varible in base64. Base64 encoding of a binary varabile will consume four base64 encoding characters for every 3 bytes of the binary variable. Padding of the unused bits is represented by an equal sign.

All that is needed to determine the count of bytes that were encoded is subtract the number of padding chars from the base64 encoded string length, divide by 4, multiple by 3, then floor the result. [ 1/4 * 3 = 3/4 = .75 ]

Continuing with your example setup:

Version 1: Base64 binary variable byte count

$ unset bin; typeset -b bin
$ read -n 10 bin < /dev/zero
$ typeset

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dnewhall
Comment options

Answer selected by dnewhall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants