The int function and its parameters

function parameters in c
what is function call in c
function prototype
void function c++
passing arguments to a function in c
functions in c
function declaration c++
function in c programming examples

I'm working on this series of problems.

I do not understand question 11 and the way int() is being used. I understand that converting x directly into an int causes the loss of some zeroes so doing that was out of the question but I'm not understanding what

intp = int(p,2) 

is suppose to be doing. Printing out intp I get the following values, 4,3,10,9. How is that at all related to 0100,0011,1010,1001? Also why are zeros lost in the first place?

Question 11 Level 2

Question: Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.



Then the output should be:


Notes: Assume the data is input by console.

Hints: In case of input data being supplied to the question, it should be assumed to be a console input.

value = []
items=[x for x in raw_input().split(',')]
for p in items:
    print p
    intp = int(p, 2)
    print intp
    if not intp%5:

print ','.join(value)

To convert binary number into Decimal, we have to use the python built-in int function, which takes the binary number and the base of number system as an argument. Example:

>>> p='1010'
>>> c=int(p,2)
>>> print c

Parameters and Arguments, Also, the function must be declared or defined, even if its return value is an integer. Example 5-1 shows how and when to declare functions passed as arguments  Parameter Description; value: A number or a string that can be converted into an integer number: base: A number representing the number format. Default value: 10

As the grumpy comments up above suggested, the int function takes a second argument, which is the base of the conversion. So it's taking the base 2 (binary) variable bound to p and turning it to a base-10 int, i.e., normal human.

C Programming Course Notes, If a function takes no parameters, the parameters may be left empty. The compiler will int add_two( int x ); // Adds 2 to its argument and returns the result main()  A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

value = []
items=[x for x in input().split(',')]
for p in items:
    intp = int(p, 2)

for x in value:
    if x%5==0:

Functions - C++ Tutorials, function example #include <iostream> using namespace std; int addition ( int a, int b) To gain access to its arguments, the function declares its parameters as  The sqrt function requires one parameter, a float, that it will use to compute the function’s return value. That is, the sqrt function gets some of the information it needs to do its job—namely, the number of which it is to compute the square root—through a parameter.

C - Functions, int max(int num1, int num2);. Parameter names are not important in function declaration only their type is required, so the following is also a valid declaration − A function called Sqrt, which is intended to compute and return the square root of its integer parameter, has been written. When the function is tested, it is observed that, although the correct value is returned, the argument passed to Sqrt is always zero after the function call.

The int function and its parameters, To convert binary number into Decimal, we have to use the python built-in int function, which takes the binary number and the base of number  The Excel INT function returns the integer part of a decimal number by rounding down to the integer. Note the INT function rounds down, so negative numbers become more negative. For example, while INT(10.8) returns 10, INT(-10.8) returns -11.

[PDF] Chapter 7 Functions, In this case the parameters are literal constants of type int LOCAL variable for second integer - INPUT When you send a parameter to a function and its. public static int getRandomNumber(int min, int max) { return (int)(Math.random() * (max – min + 1)) + min; } Here the method uses two parameters, both of type int , named min and max . Then, within the body of the method, these parameters can be used as though they were local variables.

  • Do you know what binary is?
  • read the python man page for int
  • What it turns it into is just a number. Numbers don't have any base, they only have a base when you input or output them.
  • Excellent, I think I understand now. The 2 in int(p, 2) is referring to the binary conversion, the result of which will be either (4,3,10,9) depending on which value I'm calculating and that resultant number is the base-10 which is essentially a human translation of (0100,0011,1010,1001) but the math applied to either (intp%5) will give me the same result just so happens I have to use the base-10.
  • Please consider adding some explanation to clarify your answer.
  • While this might answer the authors question, it lacks some explaining words and links to documentation. Raw code snippets are not very helpful without some phrases around it. You may also find how to write a good answer very helpful. Please edit your answer.
  • This doesn't answer the question at all.