answer.
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
Nataly
1 month ago
9

Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar

y. For an integer x, the algorithm is:As long as x is greater than 0 Output x modulo 2 (remainder is either 0 or 1) Assign x with x divided by 2Note: The above algorithm outputs the 0's and 1's in reverse order.Ex: If the input is:6the output is:0116 in binary is 110; the algorithm outputs the bits in reverse.LABACTIVITY7.14.1: LAB: Convert to binary
Computers and Technology
2 answers:
maria [1K]1 month ago
5 0

#include <stdio.h>

#include <stdlib.h>

int main ()

{

   int n, i = 1, k;

   int j;

   int binary[10];

   printf ("Enter Number \t:");

   scanf ("%d", &n);

   while (n > 0) {

       binary[i] = n % 2;

       n = n / 2;

       i = i + 1;

       k = i;

   }

   for (j = k-1; j > 0; j--)

       printf ("%d", binary[j]);

}

Further explanation

Converting numbers means changing a number into a different format that keeps the same value. Transforming decimal to binary means changing the decimal digits into binary digits of identical value.

The process involves dividing the decimal number by 2, recording the remainder each time while rounding down until zero is reached. The remainders are then read backwards to produce the binary number.

For example, converting 50 decimal to binary:

50/2=25 remainder 0

25/2=12 remainder 1

12/2=6 remainder 0

6/2=3 remainder 0

3/2=1 remainder 1

1/2=0 remainder 1

Harlamova29_29 [1K]1 month ago
4 0

Answer:

// Java Code

import java.io.*;

class Binary {

// method to convert integer to binary

static void convert(int num) {

int bin[] = new int[32];

int i=0,j;

while (num > 0) {

bin[i] = num % 2;

num = num / 2;

i++;

}

System.out.println("Number in Binary is");

for (j=i-1;j>=0;j--)

System.out.print(bin[j]);

}

public static void main(String[] args)throws IOException {

InputStreamReader x = new InputStreamReader(System.in);

BufferedReader inp = new BufferedReader(x);

int n;

System.out.println("Enter the decimal number to convert to binary");

n=Integer.parseInt(inp.readLine());

convert(n);

}

}

Explanation:

The program reads an input, creates an array for 32-bit binary numbers, repeatedly divides the input by 2 storing remainders, then prints the remainders in reverse order.

Output:

Enter the decimal number to convert to binary

6

Number in Binary is

110

You might be interested in
Given an 10-bit two's complement binary number, what is the decimal value of the largest negative integer that can be represente
Natasha_Volkova [1026]
The largest negative integer is -512.
7 0
10 days ago
Read two numbers from user input. Then, print the sum of those numbers. Hint -- Copy/paste the following code, then just type co
maria [1035]

Answer:

num1 = int(input("Input the first number "))

num2 = int(input("Input the second number "))

print(num1 + num2)

Explanation:

This code is implemented in Python programming language.

It utilizes the input function to ask the user for the first and second number.

The values are stored in the variables num1 and num2 in that order.

The print function then calculates and displays the sum of num1 and num2.

6 0
1 month ago
Read 2 more answers
Currently, this program will add 6 and 3 together, output the math problem and output the answer. Edit this code so that a rando
8_murik_8 [964]

I have attached my code in the image below. Good luck.

6 0
1 month ago
A regional trucking company landed a contract to supply products for a major retailer. To do this, it needs to hire an IT profes
zubka84 [1067]
I believe the answers are F and A
.
8 0
19 days ago
Kathy is a senior teacher in her school. She is conducting a group discussion between parents and teachers. Her role is to ensur
Amiraneli [1052]
She facilitates the discussion.
3 0
12 days ago
Read 2 more answers
Other questions:
  • You encounter another boat. You assess the situation and determine that you are the stand-on vessel. What must you do?
    15·2 answers
  • In cell F15, insert a function that will automatically display the word Discontinue if the value in cell D15 is less than 1500,
    6·1 answer
  • Splunk In most production environments, _______ will be used as the source of data input?
    12·1 answer
  • Your revenue is $22,000. Your Cost of Goods is 16,250. Your gross profit is _____________, fill in the blank,.
    14·1 answer
  • Andre is finding working in an online group challenging because there are people in the group from many different cultural backg
    15·2 answers
  • A computer program is tested by 5 independent tests. If there is an error, these tests will discover it with probabilities 0.1,
    5·1 answer
  • Which generation of programming languages provides programmers with a visual environment for coding programs?
    12·1 answer
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. PLEASE DONT F
    14·1 answer
  • Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!