>>> _char_to_string_binary('O', align=ALIGN.LEFT)
    'O----------'

    >>> _char_to_string_binary('O', align=ALIGN.RIGHT)
    '----------O'

    >>> _char_to_string_binary('O', align=ALIGN.CENTER)
    '-----O-----'
350945
def _char_to_string_binary(c, align=ALIGN.LEFT, padding='-'):
    
    s_bin = mtalk.encode(c, encoding_type='binary', letter_sep=' ')
    N = len(s_bin)
    if align == ALIGN.LEFT:
        s_align = "<"
    elif align == ALIGN.RIGHT:
        s_align = ">"
    elif align == ALIGN.CENTER:
        s_align = "^"
    else:
        raise NotImplementedError("align '%s' not allowed" % align)
    s = "{0:" + padding + s_align + str(N) + "}"
    return s.format(c)
428189
function gli_put_char(str, ch) {
    if (!str || !str.writable)
        throw('gli_put_char: invalid stream');

    if (!str.unicode) {
        if (ch < 0 || ch >= 0x100)
            ch = 63;  // '?'
    }

    str.writecount += 1;
    
    switch (str.type) {
    case strtype_File:
        if (str.streaming) {
            if (!str.unicode) {
                str.buffer4[0] = ch;
                str.fstream.fwrite(str.buffer4, 1);
            }
            else {
                if (!str.isbinary) {
                    /* cheap UTF-8 stream */
                    var len;
                    if (ch < 0x10000) {
                        len = str.buffer4.write(String.fromCharCode(ch));
                        str.fstream.fwrite(str.buffer4, len); // utf8
                    }
                    else {
                        /* String.fromCharCode chokes on astral characters;
                           do it the hard way */
                        var arr8 = UniArrayToUTF8([ch]);
                        var buf = new str.fstream.BufferClass(arr8);
                        str.fstream.fwrite(buf);
                    }
                }
                else {
                    /* cheap big-endian stream */
                    str.buffer4.writeUInt32BE(ch, 0, true);
                    str.fstream.fwrite(str.buffer4, 4);
                }
            }
        }
        else {
            /* non-streaming... */
            gli_stream_dirty_file(str);
            if (!str.unicode || (ch < 0x80 && !str.isbinary)) {
                if (str.bufpos < str.buflen) {
                    str.buf[str.bufpos] = ch;
                    str.bufpos += 1;
                    if (str.bufpos > str.bufeof)
                        str.bufeof = str.bufpos;
                }
            }
            else {
                var arr;
                if (!str.isbinary)
                    arr = UniArrayToUTF8([ch]);
                else
                    arr = UniArrayToBE32([ch]);
                var len = arr.length;
                if (len > str.buflen-str.bufpos)
                    len = str.buflen-str.bufpos;
                for (ix=0; ix<len; ix++)
                    str.buf[str.bufpos+ix] = arr[ix];
                str.bufpos += len;
                if (str.bufpos > str.bufeof)
                    str.bufeof = str.bufpos;
            }
        }
        break;
    case strtype_Memory:
        if (str.bufpos < str.buflen) {
            str.buf[str.bufpos] = ch;
            str.bufpos += 1;
            if (str.bufpos > str.bufeof)
                str.bufeof = str.bufpos;
        }
        break;
    case strtype_Window:
        if (str.win.line_request)
            throw('gli_put_char: window has pending line request');
        gli_window_put_string(str.win, CharToString(ch));
        if (str.win.echostr)
            gli_put_char(str.win.echostr, ch);
        break;
    }
}
75959
def pad(string, width, options={})
      supported = [:left, :right, :center]
      padder = options[:padder] || ' '
      align  = options[:align] || :left

      chars = string.to_s.chars.to_a
      if chars.length < width
        string = case :"#{align}"
        when :left
          string + (padder * (width - chars.length))
        when :right
          (padder * (width - chars.length)) + string
        when :center
          right = ((pad_length = width - chars.length).to_f / 2).ceil
          left = pad_length - right
          (padder * left) + string + (padder * right)
        else
          raise ArgumentError, "Alignment must be one of: #{supported.join(' ')}"
        end
      end
      string
    end
421006
def str_to_two_byte_iter(string):
    
    bstring = string.encode()
    bytes = bytearray()
    for char in bstring:
        bytes.append(char)
        bytes.append(0)
    return bytes
1018120
def to_binary_string(self, code, identifier):
        """"""
        return struct.pack(self.FORMAT, self.COMMAND, code, identifier)
9234
def to_s
      st = @char
      node = self
      while node != nil
        node = node.up
        break if node==nil
        st = node.char+st
      end
      st
    end
359892
function _substr($binary_string, $start, $length) {
        if (function_exists('mb_substr')) {
            return mb_substr($binary_string, $start, $length, '8bit');
        }
        return substr($binary_string, $start, $length);
    }
80427
def binary_encode_if_any_high_ascii(string)
      string = ensure_utf8(string)
      string.force_encoding('BINARY') if string.bytes.detect { |byte| byte > 127 }
      string
    end
914983
def bin2str(b):
    
    ret = []
    for pos in range(0, len(b), 8):
        ret.append(chr(int(b[pos:pos + 8], 2)))
    return ''.join(ret)
990837
public static char toCharValue(Object o, char defaultValue) {
	if (o instanceof Character) return ((Character) o).charValue();
	else if (o instanceof Boolean) return (char) ((((Boolean) o).booleanValue()) ? 1 : 0);
	else if (o instanceof Double) return (char) (((Double) o).doubleValue());
	else if (o instanceof Number) return (char) (((Number) o).doubleValue());
	else if (o instanceof String) {
	    String str = o.toString();
	    if (str.length() > 0) return str.charAt(0);
	    return defaultValue;

	}
	else if (o instanceof ObjectWrap) {
	    return toCharValue(((ObjectWrap) o).getEmbededObject(toCharacter(defaultValue)), defaultValue);
	}
	else if (o == null) return toCharValue("", defaultValue);
	return defaultValue;
    }
743629
def _process_string(self, char):
        

        if char in self.QUOTES:
            # end of quoted string:
            #   1) quote must match original quote
            #   2) not escaped quote (e.g. "hey there" vs "hey there\")
            #   3) actual escape char prior (e.g. "hey there\\")

            if (char == self._last_quote and
                    not self._escaped or self._double_escaped):

                # store token
                self._new_token()
                self._state = self.ST_TOKEN
                return  # skip adding token char

        elif char == self.ESCAPE:
            # escape character:
            #   double escaped if prior char was escape (e.g. "hey \\ there")

            if not self._double_escaped:
                self._double_escaped = self._escaped

        else:
            self._double_escaped = False

        self._token_chars.append(char)
1314075
def put_char(self, char, r, g, b):
		
		r, g, b = r & 0xff, g & 0xff, b & 0xff
		if(char == 0):
			char = " "

		if(char == "\r"):
			self.cursor[1] = 0
			return
		if(char == "\t"):
			for i in range(8):
				self.put_char(" ", r, g, b)
			return
		
		if(self.max_chars_per_col > self.cursor[0]):
			if(char == "\n"):
				self.cursor[1] = 0
				self.cursor[0] += 1
				return

			if(self.max_chars_per_line > self.cursor[1]):
				self.char_buffer[self.cursor[0]][self.cursor[1]] = (char, r, g, b)
				self.cursor[1] += 1
			else:
				self.cursor[0] += 1
				self.cursor[1] = 0
				self.char_buffer[self.cursor[0]][self.cursor[1]] = (char, r, g, b)
				self.cursor[1] += 1
			self.draw_char_screen()
		else:
			self.char_buffer.append([(" ", 0xff, 0xff, 0xff) for i in range(self.max_chars_per_line)])
			self.cursor[0] -= 1
			self.put_char(char, r, g, b)
636419
def _expression_to_string(expression):
    
    if isinstance(expression, BinaryExp):
        left = _expression_to_string(expression.op1)
        if isinstance(expression.op1, BinaryExp) and not (
                expression.op1.precedence > expression.precedence
                or expression.op1.precedence == expression.precedence
                and expression.associates in ('left', 'both')):
            left = '(' + left + ')'

        right = _expression_to_string(expression.op2)
        if isinstance(expression.op2, BinaryExp) and not (
                expression.precedence < expression.op2.precedence
                or expression.precedence == expression.op2.precedence
                and expression.associates in ('right', 'both')):
            right = '(' + right + ')'

        return left + expression.operator + right
    elif isinstance(expression, Function):
        return expression.name + '(' + _expression_to_string(expression.expression) + ')'
    elif isinstance(expression, Parameter):
        return str(expression)
    else:
        return format_parameter(expression)
414489
def _binary(self, node):
        
        return '[.${op}$ {left} {right} ]'\
            .format(op=latex_operator[node.operator],
                    left=self.translate(node.left),
                    right=self.translate(node.right))
1061760
def _timing_char(message):
    
    s = ''
    inter_symb = ' '
    inter_char = ' ' * 3
    inter_word = inter_symb * 7
    for i, word in enumerate(_split_message(message)):
        if i >= 1:
            s += inter_word
        for j, c in enumerate(word):
            if j != 0:
                s += inter_char
            s += _char_to_string_binary(c, align=ALIGN.LEFT)
    return s
1081826
private static char encodeChar(char c, int offset) {
		int position = (table.indexOf(c) + offset) % 52;
		return table.charAt(position);

	}
380479
def create_string_buffer(init, size=None, encoding=sys.getdefaultencoding()):
    
    if isinstance(init, six.string_types + (six.binary_type,)):
        if size is None:
            size = len(init) + 1
        buftype = c_char * size
        buf = buftype()
        try:
            buf.value = init.encode(encoding)
        except AttributeError:
            buf.value = init

        return buf
    elif isinstance(init, six.integer_types):
        buftype = c_char * init
        buf = buftype()
        return buf
    raise TypeError(init)