octal

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

这一生的挚爱 提交于 2019-11-28 01:04:52
问题 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

Why are leading zeroes used to represent octal numbers?

人盡茶涼 提交于 2019-11-27 16:02:07
I've always wondered why leading zeroes ( 0 ) are used to represent octal numbers, instead of — for example — 0o . The use of 0o would be just as helpful, but would not cause as many problems as leading 0 es (e.g. parseInt('08'); in JavaScript). What are the reason(s) behind this design choice? All modern languages import this convention from C, which imported it from B, which imported it from BCPL. Except BCPL used #1234 for octal and #x1234 for hexadecimal. B has departed from this convention because # was an unary operator in B (integer to floating point conversion), so #1234 could not be

Parse error: Invalid numeric literal

隐身守侯 提交于 2019-11-27 15:59:01
问题 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? 回答1: 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

Java int division confusing me

我的梦境 提交于 2019-11-27 15:32:39
I am doing very simple int division and I am getting odd results. This code prints 2 as expected: public static void main(String[] args) { int i = 200; int hundNum = i / 100; System.out.println(hundNum); } This code prints 1 as not expected: public static void main(String[] args) { int i = 0200; int hundNum = i / 100; System.out.println(hundNum); } What is going on here? (Windows XP Pro, Java 1.6 running in Eclipse 3.4.1) The value 0200 is an octal (base 8) constant. It is equal to 128 (decimal). From Section 3.10.1 of the Java Language Specification : An octal numeral consists of an ASCII

What are the Java semantics of an escaped number in a character literal, e.g. '\15' ?

泄露秘密 提交于 2019-11-27 09:43:12
问题 Please explain what, exactly, happens when the following sections of code are executed: int a='\15'; System.out.println(a); this prints out 13; int a='\25'; System.out.println(a); this prints out 21; int a='\100'; System.out.println(a); this prints out 64. 回答1: You have assigned a character literal, which is delimited by single quotes, eg 'a' (as distinct from a String literal, which is delimited by double quotes, eg "a" ) to an int variable. Java does an automatic widening cast from the 16

In what situations is octal base used?

别说谁变了你拦得住时间么 提交于 2019-11-27 09:00:47
I've seen binary and hex used quite often but never octal. Yet octal has it's own convention for being used in some languages (ie, a leading 0 indicating octal base). When is octal used? What are some typical situations when one would use octal or octal would be easier to reason about? Or is it merely a matter of taste? Octal is used as a shorthand for representing file permissions on UNIX systems. For example, file mode rwxr-xr-x would be 0755 . ndim Octal is used when the number of bits in one word is a multiple of 3. Examples are ancient systems with 18bit word sizes, systems with 9bit

Understanding str_pad() with leading zeros

自古美人都是妖i 提交于 2019-11-27 08:36:25
问题 I'm trying to build a php function and discovered some weird behavior and I can't even formulate a proper question, so if anyone can explain what is going on, I would appreciate it. I'm working with a set of numbers with leading zeros, and its important that they be maintained, but users almost never input leading zeros. So I use this: $x = 123; $n = 5; $x = str_pad((int)$x,$n,"0",STR_PAD_LEFT); echo $x; and, as desired, this gets me 00123. The weird stuff happens when I tested for a user

JavaScript - Preventing octal conversion

三世轮回 提交于 2019-11-27 08:19:44
问题 I'm taking a numerical input as an argument and was just trying to account for leading zeroes. But it seems javascript converts the number into octal before I can do anything to the number. The only way to work around it so far is if I pass the number as a string initially but I was hoping there'd be another way to convert it after it is passed? So far tried (using 017 which alerted me to the octal behaviour): 017.toString(10) // 15 parseInt(017,10) // 15 017 + "" //15 new Number(017) //15

int variable with leading zero?

南笙酒味 提交于 2019-11-27 02:14:36
Why is it that following results in 34? It doesn't seem to have anything to do with octal numbers. intval(042); but a leading 0 does indicate octal in many languages, as is the case here. It does have to do with octal numbers, 042 is interpreted as the octal number 42 which is 4 * 8 + 2 = 34 . Please be aware that the octal interpretation happens when the number literal is parsed while loading the PHP script. It has nothing to do with intval() , which doesn't do anything here because the value is already integer. Octal interpretation happens only with number literals, not when casting a string

Invalid Token when using Octal numbers

六月ゝ 毕业季﹏ 提交于 2019-11-27 01:43:51
问题 I'm a beginner in python and I'm trying to use a octal number in my script, but when I try it, it returns me that error: >>> a = 010 SyntaxError: invalid token (<pyshell#0>, line 1) >>> 01 SyntaxError: invalid token (<pyshell#1>, line 1) There's something wrong with my code? I'm using Python3 (and reading a python 2.2 book) 回答1: Try 0o10 , may be because of python 3, or pyshell itself. PEP says, octal literals must now be specified with a leading "0o" or "0O" instead of "0"; http://www.python