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
Can someone please help me with 6.8 Code Practice adhesive.
Ivahew [28]

Answer:

I'm looking for this one too

8 0
3 years ago
Read 2 more answers
In which of the following careers must one learn and use programming languages?
EleoNora [17]

Answer: any job that has programming in it

8 0
3 years ago
A firewall can consist of all devices positioned on the network _____________.
ale4655 [162]

Answer:

The answer to this question is "perimeter".

Explanation:

In computer science, the firewall is used to provide a network security system that manages network traffic like incoming and outgoing signals. This traffics is based on predetermined security rules. The firewall typically installs a boundary between a trusted inner network and an untrusted outer network, such as the Internet. It is a software concept and Perimeter firewalls manage the flow of network traffic and host or organization's border the boundary that provides the first line of security against outer attacks and blocking access to inappropriate content from inside an organization.

6 0
4 years ago
We look for trends when we are looking at data. What is a trend?
yulyashka [42]
A subject of what people say at the time, most used, famous at the present time
4 0
3 years ago
Read 2 more answers
Which branch of study can help Jessica study the concept of light
Fiesta28 [93]

Answer:

Physics, Quantum Mechanics

Explanation:

Light is a stream of photons with no weight. If you want to dig deeper in this mysterious phenomena, you should study physics and quantum mechanics. Physics takes up things like the theory of relativity, which can be useful in studying spacetime and how light travels through it, and quantum mechanics, being the study of matter in an atomic level, should help you get an understanding on how photons of light travel and why they behave so strangely.

4 0
3 years ago
Other questions:
  • Suppose that the following regular expression is used to recognize real numbers in scientific notation in a programming language
    14·1 answer
  • A(n application system is the master controller for all the activities that take place within a computer system. _______________
    15·1 answer
  • Methods used to change variables are called ______. equals accessors toString void mutators
    8·1 answer
  • PLEASE ANSWER THIS IM IN A QUIZ
    15·2 answers
  • SONET: is a standard for optical transmission that currently operates at Terabit per second speeds is almost identical to the IT
    7·1 answer
  • Why is proper planning important?
    10·1 answer
  • Match the different stages of boot sequence with the order in which they occur.​
    15·2 answers
  • What code would you use to create the login button?
    11·1 answer
  • When the narrator of "EPIC 2015" describes the year 2015 as the "worst of
    6·1 answer
  • You are a knowledge engineer and have been assigned the task of developing a knowledge base for an expert system to advise on mo
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!