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
Lord Strawberry, a nobleman, collected birds. He had the finest aviary in Europe, so large that eagles did not find it uncomfort
creativ13 [48]

Answer:

That was a very great story that I totally did NOT read cause it too long 0-0.

Explanation:

To my ferns.....GET ON RN CAUSE I WONLEY T^T

Anyways wuv c'alls and have a good day :3

8 0
2 years ago
After adding text to a shape, a user can make the text bold and change its color using options in the
lozanna [386]

Answer:

Top area of Word, the second segment.

Explanation:

To make it bold, press the "B" button and to change the colour press the "A" underlined with a colour (normally red).

6 0
3 years ago
What is the term for an e-mail server program that receives sent messages and delivers them to their proper destination?
Katarina [22]
MTA (Mail Transfer Agent)
6 0
3 years ago
1. Write a generic method that compares its 2 arguments using the equals method and returns true if they are equal and false oth
Ganezh [65]

Answer:

Explanation:

The following piece of code is written in Java. It creates the method as requested that takes in two generic objects and compares them using the .equals() built in Java method. This method will return True if the objects are identical or False if they are not. A test case is used in the code and the output can be seen in the attached image below.

   public static <T> boolean comparePerez(T a, T b) {

       return a.equals(b);

   }

5 0
3 years ago
Fill in the blank to complete the sentence. -------------------- is used to store and process data over the Internet using compu
Trava [24]

Answer:cloud computing

Explanation:

6 0
2 years ago
Other questions:
  • The analog signals that carry analog or digital data comprise composites built from combinations of simple sine waves.
    12·1 answer
  • What is the main difference between a literacy society and a digital Society
    9·1 answer
  • Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
    10·1 answer
  • The architecture that the large paper company Mohawk adopted enables the company to scale technology services up and down instan
    14·1 answer
  • Your it department enforces the use of 128-bit encryption on all company transmissions. your department also protects the compan
    13·1 answer
  • When does a soft page break occur in a document
    9·1 answer
  • Generally speaking, problems are rarely caused by motherboards. However, there are some instances in which a motherboard can fai
    12·1 answer
  • Help me asap ill give brainliest
    8·1 answer
  • What is smarta Art ? ​
    10·1 answer
  • How many different four-letter combinations for a locker password can you make with the lowercase and uppercase forms of the fir
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!