answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dimaraw [331]
2 years ago
6

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation

.Note: The given integer is guaranteed to fit within the range of a 32-bit signed integer. You could assume no leading zero bit in the integer’s binary representation.
Computers and Technology
1 answer:
EleoNora [17]2 years ago
5 0

Answer:

var findComplement = function(num) {

   

   var start = false;

       for (var i = 31; i >= 0; --i) {

           if (num & (1 << i)) {//find the leftmost hightest bit 1 and start from there

               start = true;

           }

           if (start) {

               

               num ^= (1 << i);

             

           }

       }

       return num;

};

var findComplement = function(num) {

   var bits = num.toString(2);

   var complement = '';

   for(var i=0;i<bits.length;i++)

   {

       complement += (bits[i]==1?0:1);

   }

   return parseInt(complement,2);

};

Explanation:

The javascript code above would accept a number in the variable complemnt and using the parseint keyword, it converts it to a binary value of that number.

Each bit is converted from the least to the most significant bit, then it is returned to the find compliment function and converted back to an integer.

You might be interested in
) A byte is used to represent a single character in the computer ______<br> true or false?
sdas [7]
Answer: false
Explanation:
7 0
2 years ago
Read 2 more answers
The OSHA Workplace Poster 3165 is optional for workplaces.<br> A) True<br> B) False
bezimeni [28]

Hello, your answer is ready.


Answer: A) True



Best of luck!


~

Your pal papaguy

5 0
2 years ago
Read 2 more answers
PLEASE HELP!!!
ollegr [7]
What are the type groups?
8 0
2 years ago
Read 2 more answers
Write a statement that assigns finalResult with the sum of num1 and num2, divided by 3. Ex: If num1 is 4 and num2 is 5, finalRes
olganol [36]

Answer:

Written using Python 3:

<em>num1 = int(input("Enter first value: ")) </em>

<em>num2 = int(input("Enter second value: ")) </em>

<em> </em>

<em>finalResult =(num1+num2) / 3 </em>

<em>print("Answer is: ", finalResult)</em>

<em />

INPUT:

Enter first value: 4

Enter second value: 5

OUTPUT:

Answer is: 3

Explanation:

First step is to declare the variables:

  • num1 and num2

Second is to ask for an input:

  • input("Enter first value: ")

Then we need to convert them into integers by encapsulating the line above inside int(). This is a requirement before you can do any mathematical operations with the given values.

  • num1 = int(input("Enter first value: "))

Next is to calculate:

  • <em>finalResult </em><em>=(num1+num2) / 3 </em>
  • Here we first add the values of num1 and num2, <em>then </em>divide the sum by 3.

And to test if the output is correct, let us print it:

  • <em>print("Answer is: "</em><em>,</em><em> </em><em>finalResult</em><em>)</em>
  • print() - when used for strings/texts, use quotation marks like: "text here"
  • but when used to print variables and numbers (integers, floats, etc), there is no need to enclose them with quotation marks.
  • to concatenate string and an integer (in this case the variable finalResult), simply add a comma right after the string.

<em />

6 0
2 years ago
Define a function below, filter_out_strs, which takes a single argument of type list. Complete the function so that it returns a
Afina-wow [57]

Answer:

Explanation:

The following code is written in Python and is a simple function that removes all of the type String elements within the list that has been passed as an argument. Then finally, prints out the list and returns it to the user.

def filter_out_str(list):

   for x in list:

       if type(x) == type(" "):

           list.remove(x)

   print(list)

   return list

8 0
2 years ago
Other questions:
  • An oil company is investigating whether they are likely to find oil at a certain site. They will use an expert system to help th
    13·1 answer
  • _________ is a term used to describe the process of recording movement of an object and translating it into a digital format..
    8·2 answers
  • Remember that ""state space"" refers to the space of all potential possibilities. Which dichotomous questions below will success
    5·1 answer
  • Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
    14·1 answer
  • Design a program that asks the user for a series of names (in no particular order). After the final person’s name has been enter
    5·1 answer
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Use the single-server drive-up bank teller operation referred to in Problems 1 and 2 to determine the following operating charac
    10·1 answer
  • Write a MATLAB function named average_of_scores_with_drops The function will have two inputs and two return values. The first in
    11·1 answer
  • +10 points~~~Which option is used in emails to inform the recipient that they should exercise discretion in accordance with shar
    12·1 answer
  • Which 2 problems does the Pay down credit card workflow solve for clients? (Select all that apply) It helps clients stay on top
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!