Posts

Showing posts with the label c programing example

WAP to convert binary to Octal number system

Write a C program to read binary number from user and convert to octal number system. How to convert from binary number system to octal number system in C. Logic to convert binary number to octal number system in C program. Example Input Input binary number: 00110111 Output Octal number: 67 Binary Number System Binary number system is a base 2 number system. Binary number system uses only 2 symbols to represent all its numbers i.e.   0   and   1 . Octal Number System Octal number system is a base 8 number system. Octal number system uses 8 symbols to represent all its numbers i.e.   0   1   2   3   4   5   6   7 Logic to convert Binary to Octal number system To make things simple and sound, I have divided the logic in two easy steps. 1.             Group all binary bits to 3 digits starting from right side. 2.        ...

WAP to find two Complement of a binary number

Write a C program to read binary number from user and find twos complement of the binary number. How to find 2's complement of a binary number in C. Logic to find twos complement of a binary number in C program. Example Input Input binary number: 01101110 Output Twos complement: 10010010 What is twos complement? Wikipedia  states, twos complement of an  N -bit number is defined as the complement with respect to  2 N . It is the result of subtracting the number from  2 N , which in binary is one followed by  N  zeroes. In simple words twos complement can be defined as sum of 1's complement of the binary number and 1. Logic to find twos complement Below is the step by step descriptive logic to find twos complement of a binary string. 1.             Read a binary string from user. Store it in some variable say  binary . 2.         ...