octal

What does an extra 0 in front of an int value mean?

跟風遠走 提交于 2019-11-30 15:00:43
Inspiring from a obfuscated piece of code, I have a small question regarding to assign value to an integer: #include <iostream> #include <cstdio> int main() { int i = 0101; std::cout << i << "\n"; } And the output was 65, and I have no idea where 65 came from? Any idea? It specifies an octal (base-8) number: 0101 == 1 * (8 * 8) + 1 == 65 . Lambert already explained that. So let me tell you what else you can do. You can write hexadecimal integer: int main() { int i = 0x101; //0x specifies this (i.e 101) is hexadecimal integer std::cout << i << "\n"; //prints 257 (1 * 16 * 16 + 1) } Output: 257

Where did the octal/hex notations come from? [closed]

[亡魂溺海] 提交于 2019-11-30 11:32:32
After all of this time, I've never thought to ask this question; I understand this came from c++, but what was the reasoning behind it: Specify decimal numbers as you normally would Specify octal numbers by a leading 0 Specify hexadecimal numbers by a leading 0x Why 0? Why 0x? Is there a natural progression for base-32? C, the ancestor of C++ and Java, was originally developed by Dennis Richie on PDP-8s in the early 70s. Those machines had a 12-bit address space , so pointers (addresses) were 12 bits long and most conveniently represented in code by three 4-bit octal digits (first addressable

Why do Java octal escapes only go up to 255?

喜夏-厌秋 提交于 2019-11-30 09:14:56
问题 The Java language specification states that the escapes inside strings are the "normal" C ones like \n and \t , but they also specify octal escapes from \0 to \377 . Specifically, the JLS states: OctalEscape: \ OctalDigit \ OctalDigit OctalDigit \ ZeroToThree OctalDigit OctalDigit OctalDigit: one of 0 1 2 3 4 5 6 7 ZeroToThree: one of 0 1 2 3 meaning that something like \4715 is illegal, despite it being within the range of a Java character (since Java characters are not bytes). Why does Java

Is 0 an octal or a decimal in C? [duplicate]

和自甴很熟 提交于 2019-11-30 07:43:47
问题 This question already has answers here : Is 0 a decimal literal or an octal literal? (3 answers) Closed 5 years ago . I have read this. It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless whether it is octal or decimal. Then he asked why is it considered as octal in C++ and decimal in Java. I said it's the standard.

Octal to sign in string from array

蹲街弑〆低调 提交于 2019-11-29 15:46:47
I want to convert octal sign like \46 to normal sign like & . The problem is that the input is created with preg_match_all() , put into an array and then retrieved. If I'd manually input the \46 octal notation into variable with double quotes, like $input="\046"; then PHP would convert it nicely. But when I have it into an array from preg_match_all() , it returns it unconverted. I want to convert it because I want to query database (mysql) that have records with "&" sign as ampersand. Carlos Lima Use stripcslashes() From the stripcslashes documentation : string stripcslashes ( string $str )

Decimal Conversion error

穿精又带淫゛_ 提交于 2019-11-29 15:25:46
I am writing a program that will convert octal numbers to decimals. It compiles right and everything but there is something majorily wrong with my conversion code. It seems perfectly logic to me, however somehow when I run the program the conversions are wrong (i.e. 1 is converted to 36) can someone point out what is going wrong? public static int convert(int octal) { int d1=0,d2=0,d3=0,d4=0,d5=0,d6=0,d7=0,d8=0; if(octal >=9999999){ d8 = (octal-(octal%10000000));} if(octal >=999999){ d7 = (octal-(octal%1000000));} if(octal >=99999){ d6 = (octal-(octal%100000));} if(octal >=9999){ d5 = (octal-

Octal representation inside a string in C

好久不见. 提交于 2019-11-29 11:50:26
In the given program: int main() { char *p = "\0777"; printf("%d %d %d\n",p[0],p[1],p[2]); printf("--%c-- --%c-- --%c--\n",p[0],p[1],p[2]); return 0; } It is showing the output as: 63 55 0 --?-- --7-- ---- I can understand that it is converting the first two characters after \0 (\077) from octal to decimal but can any one explain me why 2 characters, why not 1 or 3 or any other ? Please explain the logic behind this. char *p = "\07777"; Here a string literal assigned to a pointer to a char. "\07777" In this string literal octal escape sequence is used so first three digits represents a octal

Git: how to specify file names containing octal notation on the command line

妖精的绣舞 提交于 2019-11-29 07:30:10
For non-ASCII characters in file names, Git will output them in octal notation . For example: > git ls-files "\337.txt" If such a byte sequence does not represent a legal encoding (for the command line's current encoding), I'm not able to enter the corresponding String on command line. How can I still invoke Git commands on these files? Obviously, using the String which is displayed by git ls-files does not work: > git rm "\337.txt" fatal: pathspec '337.txt' did not match any files Tested on Windows, with msysgit 1.7.10 (git version 1.7.10.msysgit.1) In Bash, you can use printf for this kind

Is 0 an octal or a decimal in C? [duplicate]

无人久伴 提交于 2019-11-29 05:23:41
This question already has an answer here: Is 0 a decimal literal or an octal literal? 3 answers I have read this . It's octal in C++ and decimal in Java. But no description about C? Is it going to make any difference if 0 is octal or decimal? This is the question asked by my interviewer. I said no and I explained that it is always 0 regardless whether it is octal or decimal. Then he asked why is it considered as octal in C++ and decimal in Java. I said it's the standard. Please let me know what is it in C? Will it make any difference? Why are they different in different standards? juanchopanza

Parse error: Invalid numeric literal

社会主义新天地 提交于 2019-11-29 01:29:47
I have the following error while running this code below: Code: <?php $a = array(00001, 00008, 00009, 00012); print_r($a); ?> Error: Parse error: Invalid numeric literal. Why this issue occurred and how do i solve this? This comes from the changes made to how integers, specifically octals, are handled in PHP7 (as oppsoed to PHP5). From the documentation (from PHP7 migration) Invalid octal literals Previously, octal literals that contained invalid numbers were silently truncated (0128 was taken as 012). Now, an invalid octal literal will cause a parse error. From the documentation of integers