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]
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
Why did artists use pinhole cameras during the renaissance?
murzikaleks [220]
<span>Pinhole cameras were one of the most sophisticated devices of the period, it made tasks much easier it basically worked exactly like the human eye and is something just like tracing.

Hope it helps! :)</span>
3 0
3 years ago
after placing her insertion point after grandma's kitchen, order the steps Danica needs to follow to insert and format the regis
KengaRu [80]

Answer:

step 4

step 5

step 3

step 2

Explanation:

8 0
3 years ago
Read 2 more answers
What UDP port is used by a default WDS server setup when it is listening for PXE boot requests​
Vera_Pavlovna [14]
WDS uses Port 4011 to listen to PXE boot requests
8 0
2 years ago
4. Written record of all transactions in your checking account
Pachacha [2.7K]

Answer:

D) Checkbook register

Explanation:

8 0
2 years ago
Read 2 more answers
In creating a professional action plan it's important to
blagie [28]
Whenever creating a professional action plan, it might be easier to do an "if...then..." plan, or just a daily plan, like this:

Monday:
Kitchen:
 Do dishes
 Sweep floor
 Wipe counters

Bedroom:
 do laundry etc,
5 0
3 years ago
Other questions:
  • Write an interactive Python calculator program. The program should allow the user to type a mathematical expression, and then pr
    13·1 answer
  • Which of the following is an example of a good listening skill? A. Replying to the caller as "you" rather than using his or her
    9·2 answers
  • Create a detail report that will display all SCR courses in alphabetical order, with the course name and the instructor name in
    5·1 answer
  • How do I sign into raterhub on my phone and my mobile device at the same time to complete phase 2 of my raters exam for sykeshom
    10·1 answer
  • What does the CPU do in a computer?
    7·2 answers
  • How we know that how many domain exist in window server 2012?
    14·1 answer
  • What term is used to refer to the merging of government services with information technology?
    11·1 answer
  • What direction would a sprite go if you constantly increased its x property? Your answer What direction would a sprite go if you
    7·1 answer
  • What dictionary operation can you use to remove all the keys within the dictionary-named contacts?
    6·1 answer
  • What paradigm is this code based on? How do you know?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!