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
The procurement department of an organization helps to program software. <br> A)True<br> B)False
valina [46]
I think it is true absolutely
8 0
3 years ago
Read 2 more answers
Write a program that accepts a number as input, and prints just the decimal portion.
Olegator [25]

<u>Answer:</u>

<em>There are 2 ways to do extract the decimal part: </em>

<u>Explanation:</u>

  • <em>First method using number  </em>

<em>int main() { </em>

<em>  double num = 23.345; </em>

<em>  int intpart = (int)num; </em>

<em>  double decpart = num - intpart; </em>

<em>  printf(""Num = %f, intpart = %d, decpart = %f\n"", num, intpart, decpart); </em>

<em>} </em>

  • <em>Second method using string: </em>

<em>#include <stdlib.h> </em>

<em>int main() </em>

<em>{ </em>

<em>    char* inStr = ""123.4567"";          </em>

<em>    char* endptr;                       </em>

<em>    char* loc = strchr(inStr, '.'); </em>

<em>    long mantissa = strtod(loc+1, endptr); </em>

<em>    long whole = strtod(inStr, endptr);  </em>

<em>    printf(""whole: %d \n"", whole);      </em>

<em>    printf(""mantissa: %d"", mantissa);   </em>

<em>} </em>

8 0
3 years ago
Read 2 more answers
________ is a type of testing for information systems that involves programmers checking the functionality of small modules of c
Wittaler [7]

Answer:

Unit testing

Explanation:

The SDLC or the software development life cycle is a series of processes all software application must follow from birth to death of the application.

There are several stages in SDLC, they are research, design, implementation or development, deployment and maintenance. The development stage consist of case writing and testing. Examples of testing methods used are system testing and unit testing.

Unit testing involves programmers checking the functionality of small modules of code in the development phase, while system testing checks the functionality of all the small modules of code of the entire system of the information system.

3 0
3 years ago
What is a socket?a. The combination of the source and destination IP address and source and destination Ethernet addressb. The c
Zepler [3.9K]

Answer:

the combination of a source IP address and port number or a destination IP address and port number

Explanation:

Socket is a combination of a source IP address and port number or a destination IP address and port number.

3 0
3 years ago
Razer blade 15 1070 max q 144 hz ( 2018 ) vs Alienware m15 r2 luna white 1660ti 144 hz
kicyunya [14]

Answer:

I believe razor blade 15 1070

Explanation:

Because it seems more sleak

3 0
3 years ago
Other questions:
  • Define the missing method. licenseNum is created as: (100000 * customID) + licenseYear. Sample output: Dog license: 77702014
    14·1 answer
  • Which programming language looks similar to human languages?
    12·1 answer
  • What is the definition of a command computer?
    15·1 answer
  • Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in t
    10·1 answer
  • Why was Unicode invented?
    11·1 answer
  • Hi weegy, what is the latest android os?
    9·1 answer
  • What does FLUX do when soldering an electrical joint?
    13·2 answers
  • In ANSI standard C(1989) code - this is what we are teaching- declarations can occur in a for statementas in
    5·1 answer
  • ____ is Windows XP system service dispatch stubs to executables functions and internal support functions.
    13·1 answer
  • True or false windows 98 and windows xp are examples of an operating system?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!