Braille-ify a string

And no, This is not a dupe of Translate ASCII text to braille.

There are 28=256 Braille patterns in Unicode. (By 'Braille' I mean 8-cell ones)

W, wait. How many ASCII characters were there?

27 = 128?

Well then, Let's turn ASCII into Braille, 'cause there is absolutely no reason not to!

The way from ASCII, to Braille

We can see each cells represent a bit, which each cell is 'punched' or not.

Now we can allocate each cells to represent the bits of the ASCII character as binary.

(1  )(16 )
(2  )(32 )
(4  )(64 )
(8  )( - )


* ( - ) is blank

Now we can convert ASCII to Braille. For example, A(65=01000001) equals to ⠡.

Examples

Input -> Output
Braille! -> ⠢⠺⠱⡱⡴⡴⠵⠑
(Upscaled)
.. .o o. o. .. .. o. o.
o. oo .o .o .o .o .o .o
.o .o .o .o oo oo oo ..
.. .. .. o. o. o. .. ..

• Surely a is ⠱, not ⠹ (which I think is q)? – Neil Apr 21 '17 at 9:19
• @Neil The challenge isn't just "convert char codes + 10240 to chars." And yes, a is ⠱. – Erik the Outgolfer Apr 21 '17 at 9:41
• @EriktheOutgolfer I didn't suggest it was, but ⠹ would have been wrong either way, since it has the wrong number of punched cells. – Neil Apr 21 '17 at 10:05
• @Neil Oh nice. I just recalculated and found out you're right. – Matthew Roh Apr 21 '17 at 12:56
• Does it feel weird to anyone else that the LSB (bottom right) is left unused, rather than the MSB (top left)? – Julian Wolf Apr 21 '17 at 22:51

CJam, 27 26 bytes

80qf{i2b7Te[4/~\)\@+++2bc}


Try it online!

Explanation

The Braille code points are neatly ordered so that the individual dots do count up in binary. However, the ordering of the bits in the code points is different. We want the following order:

04
15
26
37


Whereas the characters are laid out in Unicode in this order:

03
14
25
67


(Which kinda makes sense, because historically, Braille only used the first six dots.) Note that we don't need the 7 dot, since the input is guaranteed to be in the ASCII range. So given a list of bits [6 5 4 3 2 1 0] of an input character, we want to reorder them into [3 6 5 4 2 1 0], to pull the bit representing the bottom-left dot to the most significant position.

80     e# Push 80... we'll need this later.
f{     e# Map this block onto each character, putting a copy of the 80
e# below each character.
i    e#   Convert the character to its code point.
2b   e#   Get its binary representation.
7Te[ e#   Pad it to 7 bits with zeros. We've now got some bit list
e#   [6 5 4 3 2 1 0].
4/   e#   Split into chunks of 4: [[6 5 4 3] [2 1 0]]
~    e#   Dump them onto the stack: [6 5 4 3] [2 1 0]
\    e#   Swap them: [2 1 0] [6 5 4 3]
)    e#   Pull off the last element: [2 1 0] [6 5 4] 3
\    e#   Swap: [2 1 0] 3 [6 5 4]
@    e#   Rotate: 3 [6 5 4] [2 1 0]
++   e#   Concatenate twice: [3 6 5 4 2 1 0]
e#   That's the reordering done.
+    e#   Prepend the 80. That puts it in the 2^7 position of the
e#   binary digit list, which gives it a value of 10240, which
e#   is where the Braille characters start.
2b   e#   Convert the bits back to an integer.
c    e#   Convert the code point to the corresponding integer.
}%

• Clever trick with the 80. – Erik the Outgolfer Apr 21 '17 at 8:58

JavaScript (ES6), 83 bytes

f=
s=>s.replace(/./g,c=>String.fromCharCode((c=c.charCodeAt())&7|c*8&64|c/2&56|10240))
<input oninput=o.textContent=f(this.value)><pre id=o>

• Oh yeah, I should probably divide by 2 before taking that AND to save a byte as well. – Martin Ender Apr 21 '17 at 10:55
• Maybe jQuery abuse can be used? – Matthew Roh Apr 21 '17 at 12:50

Python 3, 9871 66 bytes

lambda s:''.join(chr(i*8&64|i//2&56|i&7|10240)for i in map(ord,s))


Try it online!

CJam, 27 bytes

1 byte stolen from Neil.

q{i__8&8*@7&@2/56&++'⠀+}%


Try it online!

Explanation

This uses the same basic idea as my other CJam answer but uses bitwise arithmetic instead of base conversion and list manipulation to reorder the bits.

q        e# Read all input.
{        e# Map this block over each character...
i__    e#   Convert the character to its code point and make two copies.
8&     e#   AND 8. Gives the 4th bit, which we need to move to the 7th place.
8*     e#   Multiply by 8 to move it up three places.
@7&    e#   Pull up another copy and take it AND 7. This extracts the three
e#   least significant bits which shouldn't be moved at all.
@2/    e#   Pull up the last copy and divide by 2 to shift all bits down
e#   by one place.
56&    e#   AND 56. Extracts the three most-significant bits.
++     e#   Add all three components back together.
'⠀+    e#   Add to the empty Braille character which is the offset for all
e#   the code points and which converts the value to a character.
}%


PHP, 109 Bytes

foreach(str_split($argn)as$c)echo json_decode('"\u'.dechex(10240+(($d=ord($c))&7)+($d/2&56)+(($d&8)*8)).'"');


Online Version

Mathematica 100 Bytes

FromCharacterCode[10240+#~Drop~{4}~Prepend~#[[4]]~FromDigits~2&/@ToCharacterCode@#~IntegerDigits~2]&


Ungolfed:

ToCharacterCode["Braille!0"]
Prepend[Drop[#,{4}],#[[4]]]&/@%
FromDigits[#,2]&/@%
FromCharacterCode[%+10240]


+60 bytes of this tied up in long function names.

Jelly, 21 bytes

O&€“¬®p‘æ.1,8,.+“'ṁ’Ọ


Try it online!

How it works

O&€“¬®p‘æ.1,8,.+“'ṁ’Ọ  Main link. Argument: s (string)

O                      Ordinal; map all characters to their Unicode code points.
“¬®p‘               Yield the code points of the enclosed characters in Jelly's
code page, i.e., [1, 8, 112].
&€                    Take the bitwise AND of each code point to the left and the
three code points to the right.
1,8,.        Yield [1, 8, 0.5].
æ.             Take the dot product of the array to the right and each flat
array in the array to the left.
“'ṁ’   Yield 10240 = 250 × 39 + 239, where 39 and 239 are the
indices of ' and ṁ in Jelly's code page.
+       Add 10240 to all integers to the left.
Ọ  Unordinal; convert all code points to their respective
Unicode charcters.


Retina, 59 bytes

T�-- -'0-7@-GP-W\-gp-w--(-/8-?H-OX-_h-ox-⠀-⡿


Try it online! Hex dump:

0000  54 60 00 2a 07 10 2a 17  20 2a 17 30 2a 17 40 2a  T�-- -'0-7@-
0010  47 50 2a 57 5c 60 2a 67  70 2a 77 08 2a 0f 18 2a  GP-W\-gp-w--
0020  1f 28 2a 2f 38 2a 3f 48  2a 4f 58 2a 5f 68 2a 6f  (-/8-?H-OX-_h-o
0030  78 2a 7f 60 e2 a0 80 2a  e2 a1 bf                 x-⠀-⡿

C#, 63 bytes

s=>string.Concat(s.Select(c=>(char)(c*8&64|c/2&56|c&7|10240)));


Try it online!

Inspiration from @ovs and @Neil

Chip, 62 59 bytes

h*
Z~.
z.g+b
>xv<
||sf
Zx^<
Z< |
A/a/D
B/b
C/c
E/d
F/e
G/f


Try it online!

I suspect I can golf it more, just gotta figure out how...

Chip reads in each byte of input as a collection of bits, referred to by the first eight letters of the alphabet (uppercase is input, lower is output):

HGFEDCBA


We simply need to map those bits of the input to the following three bytes of output:

11100010 101000hd 10gfecba


The top half of the code is doing all the sequencing, and generates the first two bytes, the bottom half generates the third byte.

Since the specification only requires handling 7 bits for ASCII, we don't examine H. To include the eighth bit, change line B/b to B/b/H.