FAQ Database Discussion Community


Convert NSString with octal numbers to decimal int

iphone,nsstring,octal
I have an NSString with octal numbers: NSString* octal = @"247"; I'd like to convert this to an integer in base 10. If this were a hex number I could use NSScanner scanHex method, but there is no scanOct... Thanks!...

When displaying the value of variable “int a = 011”, I get 9. Why? [duplicate]

c,printf,decimal,octal,format-specifiers
This question already has an answer here: What does it mean when a numeric constant in C/C++ is prefixed with a 0? 7 answers printf with “%d” of numbers starting with 0 (ex “0102”) giving unexpected answer (ex '“66”) 3 answers With this code snippet: int a = 011;...

c++ - why the result is minus?

c++,octal
I have some problem with my simple program where if my input more than 295600127, the result is minus (-). here : #‎include‬ <iostream> #include <windows.h> using namespace std; int konarray(int b); void konbil(int A[], int &n); int kali(int x); main(){ int b; char *awal,akhir,pil; awal: system("COLOR 9F"); cout<<"enter decimal\t=...

Weird output, when number starts with 0

php,numbers,octal
1. script: $num = "00445790"; echo $num; returns: 00445790 2. script $num = 00445790; echo $num; returns: 2351 Can somebody explain why I get 2351 on the second script?...

Numeric literals in Java - octal? [duplicate]

java,literals,octal
This question already has an answer here: How does a leading zero change a numeric literal in Java? 3 answers Here is some code in java on datatypes: class Test { public static void main(String args[]) { int i = -0777; System.out.println(i); } } The output of the above...

Dealing with Octal numbers in swift

swift,octal
I can easily turn a decimal number into an octal but I'm trying to do the reverse and I've got stuck. let decimal = 11_224_393 let octString = String(rawAddress, radix: 8, uppercase: false) let octal = octString.toInt() Question I want a function that given an Int of octal digits will...

Why doesn't this error message point to the first invalid octal number in the list?

python,python-2.7,octal
I understand that a weird error I had was coming from the fact that some input numbers were interpreted as octal. But how comes, in the following line, that for example a "9" does not generate an error, but a "8" does? MY_LIST = [152,187,267,362,935,040,097,262,292,333,135,334,337,144,288,317,3 43,172,032,160,289,186,916,039,274,069,018,911,081,286,356] ^ SyntaxError: invalid token...