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
How much do taxis coast?
Novay_Z [31]
It depends on how far you travel

3 0
3 years ago
Read 2 more answers
What does the key combination ctrl+s achieve?
erastovalidia [21]
Control + S I suppose saves files
7 0
4 years ago
Read 2 more answers
How to connect two monitors for one desktop
Tems11 [23]

Answer:

two HDMI cords, this will help you your monitors

5 0
2 years ago
Read 2 more answers
In two to three sentences, describe how you would move a file.
Nina [5.8K]
<span />


You can move the file one of two ways. Your first option is to click and drag the file to another folder in the Folders pane on the left side of the window. Your second option is to right-click the file and choose Send To. Then choose from the options shown in the submenu that appears.



3 0
3 years ago
Read 2 more answers
If I execute the expression x &lt;- 4L in R, what is the class of the object `x' as determined by the `class()' function?
FinnZ [79.3K]

Answer:

integer

Explanation:

The expression can be implemented as follows:

x <- 4L

class(x)

Here x is the object. When this expression is executed in R, the class "integer" of object 'x' is determined by the class() function. R objects for example x in this example have a class attribute determines the names of the classes from which the object inherits. The output of the above expression is:

"integer"

Here function class prints the vector of names of class i.e. integer that x inherits from. In order to declare an integer, L suffix is appended to it. Basically integer is a subset of numeric. If L suffix is not appended then x<-4 gives the output "numeric". Integers in R are identified by the suffix L while all other numbers are of class numeric independent of their value.

7 0
3 years ago
Other questions:
  • What is the first step in the exchange between a web browser and a database?
    7·1 answer
  • Which of the following is a dynamic lot-sizing technique that calculates the order quantity by comparing the carrying cost and t
    10·1 answer
  • Modern ancestor of the typewriter
    12·2 answers
  • A(n) _____ uses spatial and nonspatial data and specialized techniques for storing coordinates of networks of lines (roads, rive
    8·1 answer
  • The UNIX system does not attempt to avoid cycles. Instead, it restricts access to the linking capability of the system. Normal u
    11·1 answer
  • To create a new table by using a select statement, you code the ___________________________ clause.
    14·1 answer
  • Why is it important to ensure that your software is up to date?
    13·1 answer
  • Advantages of python programming language
    10·1 answer
  • Place a check next to each of the choices that describe an example of proper ergonomics. (more than 1 answer)
    7·2 answers
  • Carl wants to add two new characters to the extraterrestrial battleship game he's
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!