Write a program that shows the binary equivalent of a given positive number between 0 to 255
Write a program that shows the binary equivalent of a given positive number between 0 to 255
Algorithm
start
step1: Read number
step2: if (number < 0 OR number > 255) then
step3: Print "Number is out of range." stop
step4: for i:=7 to 0 step -1 do
step5: bit := (number >> i) AND 1
step6: print bit
stop
Flowchart
C Programming
//Binary equivalent of a given positive number between 0 to 255.
#include <stdio.h>
int main() {
static int number,bit,i;
// Prompt the user for input
printf("Enter a number: ");
scanf("%d", &number);
// Validate the input
if (number < 0 || number > 255) {
printf("Number is out of range.\n");
return 1; // Exit with error code
}
for (i = 7; i >= 0; i--)
{
bit = (number >> i) & 1;
printf("%d", bit);
}
return 0; // Successful execution
}
OUTPUT
Enter a number: 56
00111000
๐ป Run This C Program
Write a program that shows the binary equivalent of a given positive number between 0 to 255
The selected C program is loaded automatically. Edit the code,
provide input through STDIN and click Run.
The compiler is embedded using OneCompiler. Your program runs in
the embedded C environment; Study Glance does not execute C code
directly on your web server.
Related Lab Programs
๐ข
Simple Numeric Problems
3.
Write a program that prints a multiplication table for a given number and the number of rows in the table.
View Solution โ
4.
Write a program that shows the binary equivalent of a given positive number between 0 to 255.
Current
โ
Expression Evaluation
1.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result.
View Solution โ
3.
Write a C program to find the sum of individual digits of a positive integer and test given number is palindrome.
View Solution โ
4.
A Fibonacci sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Write a C program to generate the first n terms.
View Solution โ
๐งฎ
Arrays, Pointers and Functions
1.
Write a C program to find the minimum, maximum and average in an array of integers.
View Solution โ
3.
Write a C program that uses functions to perform Multiplication of two matrices.
View Solution โ
4.
Write a program for reading elements using a pointer into an array and display the values using the array.
View Solution โ
5.
Write a program for display values reverse order from an array using a pointer.
View Solution โ
๐
Files
1.
Write a C program which copies one file to another, replacing all lowercase characters with their uppercase equivalents.
View Solution โ
๐ค
Strings
1.
Write a C program that uses functions to insert a sub-string into a given main string from a given position.
View Solution โ
2.
Write a C program that uses functions to delete n Characters from a given position in a given string.
View Solution โ
4.
Write a C program that displays the position of a character ch in the string S or โ1 if S does not contain ch.
View Solution โ
๐
Sorting and Searching
1.
Write a C program that uses non-recursive function to search for a Key value in a given list of integers using linear search method.
View Solution โ
2.
Write a C program that uses non-recursive function to search for a Key value in a given sorted list of integers using binary search method.
View Solution โ
3.
Write a C program that implements the Bubble sort method to sort a given list of integers in ascending order.
View Solution โ
4.
Write a C program that sorts the given array of integers using selection sort in descending order.
View Solution โ
5.
Write a C program that sorts the given array of integers using insertion sort in ascending order.
View Solution โ