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
Create a project for a sandwich shop. The project, named SalsSandwiches, allows a user to use a ListBox to choose a type of sand
nirvana33 [79]

Answer:

Create a new C# windows application with the name SalsSandwiches. Add the below code in respective file.

Explanation:

See attached images for the source code and output

7 0
3 years ago
What is 30 x 30 x 30 x 30
frez [133]
810,000 i asked siri
4 0
3 years ago
Read 2 more answers
Adobe Indesign project 4 museum indesign file. The instructions are 70 pages long I cant sit still long enough to read them
Alchen [17]

Answer:

? Read on to learn about the possible reasons and resolutions. ... Check whether you have the latest update installed for InDesign. ... InDesign cannot open the file when your system does not have enough memory ... Copy page elements into a new document.

Explanation:

4 0
3 years ago
Windows, Apple’s Mac OS, and Unix/Linux are just some of the most common what?
34kurt
Most common PC operating systems
7 0
3 years ago
Read 2 more answers
When preparing images to be used for different mediums print web and video in photoshop different file formats are required , se
Anika [276]
The answers are :
JPEG - Compresses well without losing quality, it should be used for the web
TIFF - Can be saved in an uncompressed file format with a high resolution, it is a common file format used for professional print services
BMP - Can be saved in a compressed or uncompressed file format, It is a common file format used for either web or print
<span>FLV or SWF - Used to publish a rendered video for use on the web</span>
5 0
3 years ago
Other questions:
  • To download a webpage, the web browser copies files and transfer them to your ____
    14·2 answers
  • How old is the oldest asian
    14·2 answers
  • Given positive integer numinsects, write a while loop that prints that number doubled without reaching 100. follow each number w
    10·1 answer
  • There are a few simple rules that you can follow to store and manage files and folders in your computer. What is the most import
    9·2 answers
  • An anagram is a word or a phrase made by transposing the letters of another word or phrase; for example, "parliament" is an anag
    7·1 answer
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    6·2 answers
  • Two time series techniques that are appropriate when the data display a strong upward or downward trend are ___________ and ____
    14·1 answer
  • How do you increase the number of tries by one?
    10·1 answer
  • State True or False: 1. Application software can run without the presence of system software. 2. . A language processor translat
    14·1 answer
  • What is the purpose of the Zoom dialog box? to put the selected range in ascending order in a query to put the selected range in
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!