Function: get-byte
get-byte is a function defined in character.c.
Signature
(get-byte &optional POSITION STRING)
Documentation
Return a byte value of a character at point.
Optional 1st arg POSITION, if non-nil, is a position of a character to get a byte value. Optional 2nd arg STRING, if non-nil, is a string of which first character is a target to get a byte value. In this case, POSITION, if non-nil, is an index of a target character in the string.
If the current buffer (or STRING) is multibyte, and the target character is not ASCII nor 8-bit character, an error is signaled.
Other relevant functions are documented in the buffer group.
Shortdoc
;; buffer
(get-byte 45)
e.g. => #xff
Source Code
// Defined in /usr/src/emacs/src/character.c
{
int c;
ptrdiff_t pos;
unsigned char *p;
if (NILP (string))
{
if (NILP (position))
{
p = PT_ADDR;
}
else
{
EMACS_INT fixed_pos = fix_position (position);
if (! (BEGV <= fixed_pos && fixed_pos < ZV))
args_out_of_range_3 (position, make_fixnum (BEGV), make_fixnum (ZV));
pos = fixed_pos;
p = CHAR_POS_ADDR (pos);
}
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
return make_fixnum (*p);
}
else
{
CHECK_STRING (string);
if (NILP (position))
{
p = SDATA (string);
}
else
{
CHECK_FIXNAT (position);
if (XFIXNUM (position) >= SCHARS (string))
args_out_of_range (string, position);
pos = XFIXNAT (position);
p = SDATA (string) + string_char_to_byte (string, pos);
}
if (! STRING_MULTIBYTE (string))
return make_fixnum (*p);
}
c = STRING_CHAR (p);
if (CHAR_BYTE8_P (c))
c = CHAR_TO_BYTE8 (c);
else if (! ASCII_CHAR_P (c))
error ("Not an ASCII nor an 8-bit character: %d", c);
return make_fixnum (c);
}