Answers for "dec to bin"

C
0

dec to bin

#include <stdio.h>
void binary(unsigned n)
{
        unsigned i;
        for (i = 1 << 31; i > 0; i >>= 1)
                (n & i)? printf("1"): printf("0");
}
int main()
{
        int i;
        printf("Enter The Number : ");
        scanf("%d", &i);
        binary(i);
        printf("\n");
        return 0;
}
Posted by: Guest on August-09-2021
2

decimal to binary

//Java Solution for Decimal To Binary Conversion

import java.util.*;
public class DecimalToBinary {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int dec = sc.nextInt();
		StringBuffer sb = new StringBuffer();
		while(dec!=0)
		{
			sb.append(dec%2);
			dec=dec/2;
		}
		System.out.println(sb.reverse());
		
	}

}
Posted by: Guest on January-29-2021

Code answers related to "C"

Browse Popular Code Answers by Language