Byte Values as Backslash Escapes
Tools disagree about how to write a byte. A hex editor shows 1B, a C string literal takes \033, tr and old printf implementations want octal too, and od prints it that way by default. When you have the hex and the tool insists on base-8, this page supplies the three digits that go after the backslash.
FF is 255, and 255 in base-8 is 377 — the largest byte an escape can name.Where Octal Escapes Still Live
Shell One-Liners
printf and tr support it everywhere, while hex escapes vary between implementations.C String Literals
Terminal control sequences are the everyday case: nearly every colour trick in a shell script begins with the escape character, written \033 far more often than \x1B.
Converting One Byte at a Time
Enter a single byte
Two hex digits at a time keeps the answer inside the 000 to 377 range that a byte escape allows. Longer input is converted happily, but the result is no longer one byte.
Pad the answer to three digits
Escapes are conventionally written with all three positions, so a result of 12 becomes \012. The zeros change nothing numerically but stop the next character being read as part of the escape.
Adjust the marker for your language
The copy button gives 0o notation, which suits Python and modern JavaScript. A C literal or a shell command needs a backslash instead, so swap the prefix as you paste.
Octal Escape Sequences for Single Bytes
These are the bytes that turn up most often in scripts and protocol work, written in both notations so you can match whichever one your tooling prints.
| Hex | Octal escape | Byte | What it is |
|---|---|---|---|
07 | \007 | 7 | Bell, the terminal beep |
0A | \012 | 10 | Line feed, the Unix newline |
1B | \033 | 27 | Escape, the start of a colour sequence |
41 | \101 | 65 | Capital A in ASCII |
7F | \177 | 127 | Delete, the last ASCII code |
C2 | \302 | 194 | A UTF-8 lead byte for Latin-1 characters |
Three-Digit Spacing by Default
Octal output is grouped in threes, which happens to be exactly the width of one byte escape.
Backslashes Never Reach the Field
Paste \x1B and only the hex characters survive, so an escape copied out of source code converts without cleanup.
One Byte per Shareable Link
Add ?v=1B to the address and the page opens with that byte already translated for a note or a code review.
Escape Sequence Questions
Why can't I translate each hex digit into octal separately?
A hex digit carries four bits and an octal digit three, so the groups cross each other. Only the value survives the trip, which is why the conversion runs through the number rather than digit by digit.
How many octal digits does one byte need?
Three, and the first of them can only be 0 to 3. A byte tops out at 377, so a fourth digit means the value no longer fits in eight bits.
Should I use an octal escape or a hex one in C?
Octal has a fixed limit of three digits, while a hex escape keeps consuming valid characters — "\x1Bc" is ambiguous in a way "\033c" is not. That predictability is why old code favours base-8.
Does the 0o marker belong in a shell command?
No. That prefix is Python and JavaScript syntax. A shell wants a backslash and the digits, as in printf '\101', and chmod wants bare digits with nothing in front.
Can I convert a whole hex dump line at once?
The spaces between the bytes are stripped on entry, so the line would merge into one enormous number and the octal digits would no longer align with byte boundaries. Convert byte by byte.
No comments yet. Be the first to comment!