1answer.
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]
3 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]3 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
The AND operator is a disjunction and the OR operator is a conjunction.
qwelly [4]

Answer:

True but it might be false but i think is true

8 0
2 years ago
Type the correct answer in the box. Spell all words correctly. Complete the sentence below that describes an open standard in vi
Anika [276]

Answer:

digital

Explanation:

Today, video production has become digital, and all playback devices work on the open standard known as digital technology.​

8 0
3 years ago
What kind of word is the pronoun in bold letters?
tresset_1 [31]

Answer:

Subject

Explanation:

The kind of word that is pronoun in bold letters is "Subject".

In Example

We get our paychecks on Friday, and I always need mine.

There We and I are subjects.

5 0
3 years ago
Read 2 more answers
Research current rates of monetary exchange. Draw a flowchart or write pseudocode to represent the logic of a program that allow
Anastasy [175]

Explanation:

Start

Input dollars

Set Euros = 0.91 * dollars

Set Yens = 109.82 * dollars

Output Euros

Output Yens

Stop

Note: The rates are as of 07-Feb-2020

7 0
3 years ago
Is windows 7 professional faster than home premium?
Olin [163]
Widows 7 is no longer supported for anti virus, I recommend a windows 10 license
8 0
2 years ago
Other questions:
  • What type of user account should Tuan’s brother use?
    10·1 answer
  • How is the JOptionPaneclass used to display a dialog box that performs a yes/noconfirmation?
    10·1 answer
  • What are the differences between a trap (aka software interrupt) and an interrupt (hardware interrupt)? What is the use of each
    12·1 answer
  • Define the following BASIC terms:<br> 1. Keywords<br> 2. Constants<br> 3.Variables
    8·1 answer
  • Which of the following is not a key way that a LAN shares
    15·1 answer
  • n what sense is it now possible for a country to be ""occupied"" by an invisible invader that arrives through airwaves and wirel
    6·1 answer
  • Which of the following will increase the level of security for personal and confidential information on a mobile device if the d
    14·1 answer
  • Stephanie would like to know the average number of regular hours worked by her employees. In cell B11, create a formula using th
    8·1 answer
  • Which of the following examples can be solved with unsupervised learning?
    8·1 answer
  • __________ can collect information about credit card numbers.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!