What do you mean by '\o<octal number>'?

  • Thread starter Thread starter dE_logics
  • Start date Start date
  • Tags Tags
    Mean
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 4K views
dE_logics
Messages
742
Reaction score
0
book said:
In addition, an arbitrary byte-sized bit pattern can be specified by

'\ooo'

where ooo is one to three octal digits (0...7) or by "
I'm not sure what they mean here...can someone explain?

When ever I do, for e.g -

"\o7" or "\o42" in printf to try and print ASCII code 7 or 52 (decimal)

Compiler returns \o is not recognized.

However if I do "\07" or "\042" I get the characters 7 and 52 (as in ASCII code).


My question is, what is this 'o'?
 
Physics news on Phys.org
You can use "\ooo" where "ooo" is 1 to 3 octal digits. In other words, "ooo" can be "1", "304", "12", "77"...but not "o12."

You can also use "\xhh", where "hh" is 1 or 2 hexadecimal digits...ie, "\x34" or "\x9f" or "\xb."

This is the complete ascii table:
http://www.cs.utk.edu/~pham/ascii_table.jpg

Some of the characters have special escape codes defined, such as "\n" for newline, which has hex value "A" and octal value "012", therefore the following are all equivalent:

\n
\xa
\xA (pretty sure this is case insensitive)
\012
\12 (im pretty sure the leading zero can be dropped)
 
Last edited by a moderator:
dE_logics said:
However if I do "\07" or "\042" I get the characters 7 and 52 (as in ASCII code).
Octal \042 is the code for the character with ASCII code 34, not 52. This character is the double-quote, ".
 
junglebeast said:
(im pretty sure the leading zero can be dropped)

Yes it can.

Thanks everyone!