octal

How to use Python to convert an octal to a decimal

廉价感情. 提交于 2019-12-05 04:57:34
I have this little homework assignment and I needed to convert decimal to octal and then octal to decimal. I did the first part and can not figure out the second to save my life. The first part went like this: decimal = int(input("Enter a decimal integer greater than 0: ")) print("Quotient Remainder Octal") bstring = " " while decimal > 0: remainder = decimal % 8 decimal = decimal // 8 bstring = str(remainder) + bstring print ("%5d%8d%12s" % (decimal, remainder, bstring)) print("The octal representation is", bstring) I read how to convert it here: Octal to Decimal but have no clue how to turn

HELP! I don't know binary, hexadecimal, octal, and bit-wise

萝らか妹 提交于 2019-12-04 13:44:30
问题 I haven't learned this in programming class before, but now I need to know it. What are some good resources for learning these numbers and how to convert them? I pretty much am going to memorise these like the times table. 回答1: In our everyday decimal system, the base number, or radix is 10 . A number system's radix tells us how many different digits are in use . In decimal system we use digits 0 through 9 . The significance of a digit is radix ^ i , where i is digit's position counting from

What is an Illegal octal digit?

天涯浪子 提交于 2019-12-04 03:02:32
I'm trying to make an array of zip codes. array = [07001, 07920] This returns : array = [07001, 07920] ^ from (irb):12 from :0 Never seen this before. Any workarounds? Yuliy Ruby is interpreting numbers that have a leading 0 as being in octal (base 8). Thus the digits 8 and 9 are not valid. It probably makes more sense to store ZIP codes as strings, instead of as numbers (to avoid having to pad with zeroes whenever you display it), as such: array = ["07001", "07920"] Numbers that start with 0 are assumed to be in octal format, just like numbers that start with 0x are assumed to be in

Octal to sign in string from array

人盡茶涼 提交于 2019-12-03 18:12:19
问题 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. 回答1:

HELP! I don't know binary, hexadecimal, octal, and bit-wise

て烟熏妆下的殇ゞ 提交于 2019-12-03 08:42:05
I haven't learned this in programming class before, but now I need to know it. What are some good resources for learning these numbers and how to convert them? I pretty much am going to memorise these like the times table. In our everyday decimal system, the base number, or radix is 10 . A number system's radix tells us how many different digits are in use . In decimal system we use digits 0 through 9 . The significance of a digit is radix ^ i , where i is digit's position counting from right, starting at zero. Decimal number 6789 broken down: 6 7 8 9 radix ^ i | | | | -------------- | | | +--

Decimal to Octal Conversion [duplicate]

♀尐吖头ヾ 提交于 2019-12-02 23:13:17
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Decimal Conversion error I am writing a program for a class and is having trouble figuring how to convert an octal number to an decimal number. Here is what I been trying to do so far: import java.util.Scanner; public class test { public static void main ( String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter number: "); int oct = input.nextInt(); int d2count = 0; int result=0; int

Decimal to Octal Conversion [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 12:59:43
Possible Duplicate: Decimal Conversion error I am writing a program for a class and is having trouble figuring how to convert an octal number to an decimal number. Here is what I been trying to do so far: import java.util.Scanner; public class test { public static void main ( String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter number: "); int oct = input.nextInt(); int d2count = 0; int result=0; int d3count = 0; int d3 = 0; int d2 = 0; d3 = oct; d2 = oct; if(oct < 1000){ while ( d3 >= 100){ d3 = d3 - 100; d3count++; }} if (oct < 100){ while ( d2 >= 10){ d2 = d2 -

Weird output, when number starts with 0

有些话、适合烂在心里 提交于 2019-12-02 09:44:01
问题 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? 回答1: Integers that start with zero are consider octal. Because octal integers only use numbers from 0 to 8 everything from the 9 on are ignored. So 00445790 becomes 004457 which is 2351 in decimal. 来源: https://stackoverflow.com/questions/30629817/weird-output-when-number-starts-with-0

Weird output, when number starts with 0

旧街凉风 提交于 2019-12-02 07:48:19
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? John Conde Integers that start with zero are consider octal. Because octal integers only use numbers from 0 to 8 everything from the 9 on are ignored. So 00445790 becomes 004457 which is 2351 in decimal. 来源: https://stackoverflow.com/questions/30629817/weird-output-when-number-starts-with-0

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

烂漫一生 提交于 2019-12-02 01:28:57
问题 This question already has answers 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) Closed 4 years ago . With this code snippet: int a = 011; printf("a = %d", a); Why is the result a = 9 回答1: 011 is an octal value and its decimal equivalent is 9. Preceding integer literal with 0 indicates octal value. Use %o specifier in printf to print the value in