8 added 1 character in body
source | link


Diverse notations in one otputoutput, e.g. for packed data:


Diverse notations in one otput, e.g. for packed data:


Diverse notations in one output, e.g. for packed data:

    Tweeted twitter.com/StackCodeGolf/status/870080255930888193
    Post Reopened by Stephen, Timtech, Wheat Wizard, Julian Lachniet, ETHproductions
7 clarified the specs
source | link

EyballingEyeballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation.
So I want to take a number, say 3 (00000011) and output the bits in user-defined format, like for example with space separated pairs:

or, say, in reversed order and with some decorators, e.g.:

Furthermore I'd like, there must be possibilty to substitute the characters used forshow '0' and '1' as custom characters to distinguish them better, e.g.:

So the challenge is to write the code which does that all whithin the following specification. 

The function takes input like this:
   f(A, mask, zeros, ones)

A - this is the- input number, it can be -- any (unsigned) integer in range 0-255.
mask -- a string parameter which defines the construction of the output.
zeros -- a string of the same length, defines 'zero' characterglyphs for each output slot.
ones -- a string of the same length, defines 'one' characterglyphs for each output slot.

Let's sayLook at program start A is converted into a bitstring or a list of bits. So each bit of A will be 0-indexed, namely A[0] will be the leftmost bit (msb) and A[7]this image with example closely to understand how the rightmost bit (lsb). output is generated:

Given a mask e.g. "0 foo 123",enter image description here

So only the algorithm takes each digit presentsingle digits in the mask stringare parsed and replaces itreplaced by the corresponding bitbits of A, i.eother characters are left as is. here 0,1,2 and 3 will be replaced by bits A[0], A[1]Further, A[2] and A[3]. Everything else is left asif the value of the taken bit is, and 1 then it shows up in the final output string will have the same length as the mask string"X" and if it is 0 then it shows up as "o". E.gIn the above example all four taken bits are "1" so we see "X" in all slots. for A=255 (11111111) this will give:

1 foo 111

FurtherIf the input number was 128, characters fromthen, logically, the output would be zerosX foo bar ooo. Characters in parameters "zeros" and "ones": any printable ASCII chars, assume they are always char-aligned with the mask.

onesNotes show up instead of "0" and "1" in:

  • Bits are 0-indexed: 0th bit is the MSB.
  • Assume that digits 8,9 are not allowed in the mask string.
  • Input Strings include any printable ASCII chars.
  • 'Zeros' and 'ones' are char-aligned with the mask.
  • For special characters/modifiers in your language: we can assume they will not appear in the input string.

For the same slotsclarity, in this case:see more examples.

mask =   "0 foo 123"
zeros=   "o     ooo"
ones =   "X     XXX"

A=255 ->  X foo XXX
A=128 ->  X foo ooo 

Input -> Output examples

Example 2: to outputOutput all 8 bits in common order with a space delimiter and, in common oval-and-stick notation:

mask  =  "0123 4567"  
zeros =  "0000 0000"  
ones  =  "1111 1111"  

A=1 ->    0000 0001

Example 3:
Output in reversed bits asorder, in dash and "s"-and-glyph notation: 

mask =    "| 7654 3210 |"
zeros=    "  ---- ----  "
ones =    "  ssss ssss  "

A=1  ->    | s--- ---- |
A=128->    | ---- ---s |

Notes:

Digits 8,9 are not allowed in the mask string, no error checking is needed.
Parameters include only single ASCII chars. 'Zeros' and 'ones' are assumed char-aligned with the mask. If some characters are not allowed in strings in your language, you can assume they will not appear in the input.

More Input->Output examples

Example #1

mask =       "0123 4567"
zeros=       "---- ----"
ones =       "ssss ssss"

A= 0   ->     ---- ----
A= 1A=3   ->     ----| -ss--s
A= 2   ->     ---- --s-|
A= 3   A=128->    | ---- --ss
A= 128 ->     s--- ----
A= 255 ->     ssss ssss|

Example #2
Diverse notations in one otput, e.g. for packed data:

Example #3
Repeating patterns:

The rules have been slightly simplified - the program must outputprint one number only (not array/list of numbers as it was initially proposed initially).

Eyballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation.
So I want to take a number, say 3 (00000011) and output the bits in user-defined format, like for example space separated pairs:

or, say in reversed order and with some decorators, e.g.:

Furthermore I'd like to substitute the characters used for '0' and '1' to distinguish them better, e.g.:

So the challenge is to write the code which does that whithin the following specification.

The function takes input like this:
 f(A, mask, zeros, ones)

A - this is the input number, it can be any (unsigned) integer in range 0-255.
mask - a string parameter which defines the construction of the output.
zeros - a string of the same length, defines 'zero' character for each output slot.
ones - a string of the same length, defines 'one' character for each output slot.

Let's say at program start A is converted into a bitstring or a list of bits. So each bit of A will be 0-indexed, namely A[0] will be the leftmost bit (msb) and A[7] the rightmost bit (lsb).

Given a mask e.g. "0 foo 123", the algorithm takes each digit present in the mask string and replaces it by the corresponding bit of A, i.e. here 0,1,2 and 3 will be replaced by bits A[0], A[1], A[2] and A[3]. Everything else is left as is, and the output string will have the same length as the mask string. E.g. for A=255 (11111111) this will give:

1 foo 111

Further, characters from zeros and ones show up instead of "0" and "1" in the same slots, in this case:

mask =   "0 foo 123"
zeros=   "o     ooo"
ones =   "X     XXX"

A=255 ->  X foo XXX
A=128 ->  X foo ooo 

Example 2: to output all 8 bits in common order with a space delimiter and in common oval-and-stick notation:

mask  = "0123 4567"  
zeros = "0000 0000"  
ones  = "1111 1111"  

A=1 ->   0000 0001

Example 3: reversed bits as dash and "s":

mask =    "| 7654 3210 |"
zeros=    "  ---- ----  "
ones =    "  ssss ssss  "

A=1  ->    | s--- ---- |
A=128->    | ---- ---s |

Notes:

Digits 8,9 are not allowed in the mask string, no error checking is needed.
Parameters include only single ASCII chars. 'Zeros' and 'ones' are assumed char-aligned with the mask. If some characters are not allowed in strings in your language, you can assume they will not appear in the input.

More Input->Output examples

Example #1

mask =       "0123 4567"
zeros=       "---- ----"
ones =       "ssss ssss"

A= 0   ->     ---- ----
A= 1   ->     ---- ---s
A= 2   ->     ---- --s-
A= 3   ->     ---- --ss
A= 128 ->     s--- ----
A= 255 ->     ssss ssss

Example #2

Example #3

The rules have been slightly simplified - the program must output one number only (not array/list of numbers as was initially proposed).

Eyeballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation.
So I want to take a number, say 3 (00000011) and output the bits in user-defined format, for example with space separated pairs:

or, say, in reversed order and with some decorators, e.g.:

Furthermore, there must be possibilty to show '0' and '1' as custom characters to distinguish them better, e.g.:

So the challenge is to write the code which does that all whithin the following specification. 

The function takes input like this:  f(A, mask, zeros, ones)

A -- input number -- any (unsigned) integer in range 0-255.
mask -- a string parameter which defines the construction of the output.
zeros -- a string of the same length, defines 'zero' glyphs for each output slot.
ones -- a string of the same length, defines 'one' glyphs for each output slot.

Look at this image with example closely to understand how the output is generated:

enter image description here

So only the single digits in the mask are parsed and replaced by corresponding bits of A, other characters are left as is. Further, if the value of the taken bit is 1 then it shows up in the final output as "X" and if it is 0 then it shows up as "o". In the above example all four taken bits are "1" so we see "X" in all slots.

If the input number was 128, then, logically, the output would be X foo bar ooo. Characters in parameters "zeros" and "ones": any printable ASCII chars, assume they are always char-aligned with the mask.

Notes:

  • Bits are 0-indexed: 0th bit is the MSB.
  • Assume that digits 8,9 are not allowed in the mask string.
  • Input Strings include any printable ASCII chars.
  • 'Zeros' and 'ones' are char-aligned with the mask.
  • For special characters/modifiers in your language: we can assume they will not appear in the input string.

For the clarity, see more examples.

Input -> Output examples

Output all 8 bits in common order with a space delimiter, in common oval-and-stick notation:

mask  =  "0123 4567"  
zeros =  "0000 0000"  
ones  =  "1111 1111"  

A=1 ->    0000 0001


Output in reversed order, in dash-and-glyph notation: 

mask =    "| 7654 3210 |"
zeros=    "  ---- ----  "
ones =    "  ssss ssss  "

A=1  ->    | s--- ---- |
A=3   ->   | ss-- ---- |
A=128->    | ---- ---s |


Diverse notations in one otput, e.g. for packed data:


Repeating patterns:

The rules have been slightly simplified - the program must print one number only (not array/list of numbers as it was proposed initially).

6 better intro
source | link

Eyballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation. A
So I want to take a number can be any unsigned integer from 0, say 3 (00000011) and output the bits in user-defined format, like for example space separated pairs:

00 00 00 11

or, say in reversed order and with some decorators, e.g.:

11_00_00_00

Furthermore I'd like to 255substitute the characters used for '0' and '1' to distinguish them better, e.g.:

XX oo oo oo

So the outputchallenge is constructed according to specific formatter parameterswrite the code which does that whithin the following specification.  

A - this is a number that must be printed out in binary representation according to the other three parameters, see explanation and examples below. Theinput number, it can be any (unsigned) integer in range 0-255.
mask - a string parameter which defines the construction of the output.
zeros - a string of the same length, defines 'zero' character for each output slot.
ones - a string of the same length, defines 'one' character for each output slot.

All strings contain ASCII characters only and are passed as strings.

Let's say at program start A is converted into a bitstring or a list of bit valuesbits. So each bit of A will be indexed starting with 0-indexed, i.enamely A[0] will be the leftmost bit (msb) and A[7] the rightmost bit (lsb).

Given a maskmask e.g. "0 foo 012"123", the algorithm takes each digit present in the mask string and replaces it by the corresponding bit of A, i.e. here 0,1,2 and 23 will be replaced by valuesbits A[0], A[1], A[2] and A[3]. Everything else is left as is, soand the output resultstring will have the same length as the mask string. Digits 8,9 are not allowed in the mask, so no additonal value check is neededE.
The bit values in output however are printed not as "0" and "1" characterg. for A=255 (11111111) this will give:

1 foo 111

Further, but as a custom character defined in the parameterscharacters from zeros and ones.

e.g input show up instead of "0" and "1" in the same slots, in this case:  

mask  = "0123 4567" "0 foo 123"
zeroszeros= = "0000 0000""o     ooo"
ones  = "1111 1111" "X     XXX"

A=255 ->  X foo XXX
A=128 ->  X foo ooo 

will construct theExample 2: to output with all 8 bits in common order with a space delimiter and in common oval-and-stick notation:

mask  = "0123 4567"  
zeros = "0000 0000"  
ones  = "1111 1111"  

A=1 ->   0000 0001

Another exampleExample 3:  reversed bits as dash and "s":

mask =    "| 7654 3210 |"
zeros=    "  ---- ----  "
ones =    "  ssss ssss  "

will construct the decorated output of all 8 bits in reversed order and zero values printed as dash "-" and one values printed as "s":

 
A=1   -> "|   | s--- ---- |"|
A=128 -> "|   | ---- ---s |"|

All parameter stringsNotes:

Digits 8,9 are assumed char-aligned withnot allowed in the mask andstring, no error checking is needed.
Parameters include only single ASCII chars. 'Zeros' and 'ones' are assumed char-aligned with the mask. If some characters are not allowed in strings in your language, you can assume they will not appear in the input.

InputMore Input->Output examples

mask =       "0123 4567"
zeros=       "---- ----"
ones =       "ssss ssss"

A= 0   ->     ---- ----
A= 1   ->     ---- ---s
A= 2   ->     ---- --s-
A= 3   ->     ---- --ss
A= 128 ->     s--- ----
A= 255 ->     ssss ssss
mask =       "0 | 123 4567"
zeros=       "    --- ----"
ones =       "X   kkk ssss"

A= 15  ->       | --- ssss
A= 16  ->       | --k ----
A= 32  ->       | -k- ----
A= 128 ->     X | --- ----
A= 255 ->     X | kkk ssss
mask =    "| 7 66 555 4444 |"
zeros=    "  . .. ... ....  "
ones =    "  0 00 000 0000  "

A= 0 ->    | . .. ... .... |
A= 1 ->    | 0 .. ... .... |
A= 2 ->    | . 00 ... .... |
A= 3 ->    | 0 00 ... .... |
A= 4 ->    | . .. 000 .... |

Eyballing the binary values printed as ovals and sticks is not easy... To help with that, you must write a function (or program) that prints numbers in custom binary representation. A number can be any unsigned integer from 0 to 255 and the output is constructed according to specific formatter parameters.  

A - this is a number that must be printed out in binary representation according to the other three parameters, see explanation and examples below. The number can be any (unsigned) integer in range 0-255.
mask - a string parameter which defines the construction of the output.
zeros - a string of the same length, defines 'zero' character for each output slot.
ones - a string of the same length, defines 'one' character for each output slot.

All strings contain ASCII characters only and are passed as strings.

Let's say at program start A is converted into a bitstring or a list of bit values. So each bit of A will be indexed starting with 0, i.e A[0] will be the leftmost bit (msb) and A[7] the rightmost bit (lsb).

Given a mask e.g. "0 foo 012", the algorithm takes each digit present in the mask string and replaces it by the corresponding bit of A, i.e. here 0,1 and 2 will be replaced by values A[0], A[1], A[2]. Everything else is left as is, so the output result will have the same length as the mask string. Digits 8,9 are not allowed in the mask, so no additonal value check is needed.
The bit values in output however are printed not as "0" and "1" character, but as a custom character defined in the parameters zeros and ones.

e.g input:  

mask  = "0123 4567"  
zeros = "0000 0000"  
ones  = "1111 1111"  

will construct the output with all 8 bits in common order with a space delimiter and in common oval-and-stick notation:

A=1 -> 0000 0001

Another example:  

mask = "| 7654 3210 |"
zeros= "  ---- ----  "
ones = "  ssss ssss  "

will construct the decorated output of all 8 bits in reversed order and zero values printed as dash "-" and one values printed as "s":

A=1   -> "| s--- ---- |"
A=128 -> "| ---- ---s |"

All parameter strings are assumed char-aligned with the mask and include only single ASCII chars. If some characters are not allowed in strings in your language, you can assume they will not appear in the input.

Input->Output examples

mask = "0123 4567"
zeros= "---- ----"
ones = "ssss ssss"

A= 0   ->     ---- ----
A= 1   ->     ---- ---s
A= 2   ->     ---- --s-
A= 3   ->     ---- --ss
A= 128 ->     s--- ----
A= 255 ->     ssss ssss
mask = "0 | 123 4567"
zeros= "    --- ----"
ones = "X   kkk ssss"

A= 15  ->       | --- ssss
A= 16  ->       | --k ----
A= 32  ->       | -k- ----
A= 128 ->     X | --- ----
A= 255 ->     X | kkk ssss
mask = "| 7 66 555 4444 |"
zeros= "  . .. ... ....  "
ones = "  0 00 000 0000  "

A= 0 ->    | . .. ... .... |
A= 1 ->    | 0 .. ... .... |
A= 2 ->    | . 00 ... .... |
A= 3 ->    | 0 00 ... .... |
A= 4 ->    | . .. 000 .... |

Eyballing the binary values printed as ovals and sticks is not so easy... To help with that, you must write a function (or a program) that prints numbers in custom binary representation.
So I want to take a number, say 3 (00000011) and output the bits in user-defined format, like for example space separated pairs:

00 00 00 11

or, say in reversed order and with some decorators, e.g.:

11_00_00_00

Furthermore I'd like to substitute the characters used for '0' and '1' to distinguish them better, e.g.:

XX oo oo oo

So the challenge is to write the code which does that whithin the following specification.

A - this is the input number, it can be any (unsigned) integer in range 0-255.
mask - a string parameter which defines the construction of the output.
zeros - a string of the same length, defines 'zero' character for each output slot.
ones - a string of the same length, defines 'one' character for each output slot.

Let's say at program start A is converted into a bitstring or a list of bits. So each bit of A will be 0-indexed, namely A[0] will be the leftmost bit (msb) and A[7] the rightmost bit (lsb).

Given a mask e.g. "0 foo 123", the algorithm takes each digit present in the mask string and replaces it by the corresponding bit of A, i.e. here 0,1,2 and 3 will be replaced by bits A[0], A[1], A[2] and A[3]. Everything else is left as is, and the output string will have the same length as the mask string. E.g. for A=255 (11111111) this will give:

1 foo 111

Further, characters from zeros and ones show up instead of "0" and "1" in the same slots, in this case:

mask =   "0 foo 123"
zeros=   "o     ooo"
ones =   "X     XXX"

A=255 ->  X foo XXX
A=128 ->  X foo ooo 

Example 2: to output all 8 bits in common order with a space delimiter and in common oval-and-stick notation:

mask  = "0123 4567"  
zeros = "0000 0000"  
ones  = "1111 1111"  

A=1 ->   0000 0001

Example 3: reversed bits as dash and "s":

mask =    "| 7654 3210 |"
zeros=    "  ---- ----  "
ones =    "  ssss ssss  "
 
A=1  ->    | s--- ---- |
A=128->    | ---- ---s |

Notes:

Digits 8,9 are not allowed in the mask string, no error checking is needed.
Parameters include only single ASCII chars. 'Zeros' and 'ones' are assumed char-aligned with the mask. If some characters are not allowed in strings in your language, you can assume they will not appear in the input.

More Input->Output examples

mask =       "0123 4567"
zeros=       "---- ----"
ones =       "ssss ssss"

A= 0   ->     ---- ----
A= 1   ->     ---- ---s
A= 2   ->     ---- --s-
A= 3   ->     ---- --ss
A= 128 ->     s--- ----
A= 255 ->     ssss ssss
mask =       "0 | 123 4567"
zeros=       "    --- ----"
ones =       "X   kkk ssss"

A= 15  ->       | --- ssss
A= 16  ->       | --k ----
A= 32  ->       | -k- ----
A= 128 ->     X | --- ----
A= 255 ->     X | kkk ssss
mask =    "| 7 66 555 4444 |"
zeros=    "  . .. ... ....  "
ones =    "  0 00 000 0000  "

A= 0 ->    | . .. ... .... |
A= 1 ->    | 0 .. ... .... |
A= 2 ->    | . 00 ... .... |
A= 3 ->    | 0 00 ... .... |
A= 4 ->    | . .. 000 .... |
5 deleted 2 characters in body
source | link
4 added 727 characters in body
source | link
3 simplified rules and explanation
source | link
    Post Closed as "unclear what you're asking" by Stephen, Rɪᴋᴇʀ, Wheat Wizard, Conor O'Brien, Mego
2 deleted 135 characters in body
source | link
1
source | link