Posts

Showing posts with the label decimal number

Binary to Decimal conversion -Bitwise Left shift Operator

Binary to decimal conversion using Bitwise Left-shift Operator - algorithm Declaration Input Read char bits[9] Output integer decval Temp var integer n=0,len=0       len = strlen(bits) Loop n=0 to len-1 decval left shift by 1 bits[n] == '1' then decval OR by 1 decval left shift by 1 End Loop Output print,bits Binary to Decimal conversion by Left-shift -C programming code The C programming code converts binary bits into a decimal value by bitwise left-shift operator. The input binary bits are given to the program while it is running and returns a decimal value as conversion result. # include <stdio.h> # include < string .h> int main () { int decval; char bits[9]; int n=0; printf ("\n Bitwise Left-shift Operat or Decimal Conversion"); printf("\n Enter a binary bits :" ); scanf("%s", &bits); ...

Binary to Decimal conversion

Image
The binary number consists of 0's and 1's such a number system has only two distinct digits : {0,1} is called base-2 number system and The decimal number consist of 0's to 9's such a number system has 10 distinct digits {0,1,2,3,4,5,6,7,8,9} is called base 10 number system. The binary to decimal conversion is carried out by following manner. Binary to Decimal - Example of Manual Conversion example given binary bits=10101 convert it into decimal value =? decimal value =1x2^4 + 0x2^3 + 1x2^2 + 0x2^1 + 1x2^0 =1x16 + 0x8 + 1x4 + 0x2 + 1x1 =16 + 0 + 4 + 0 + 1 decimal value = 21 Binary to Decimal conversion - algorithm Declaration Input Read char bits Output integer decval Temp var char abit; integer len,n=0     len = strlen(bits) Loop n =0 to len-1 abit= bits[len-n-1] ...

Decimal to 8 bit Binary conversion

Image
The binary number has two digits {0,1} is called base-2 number system, while the decimal number system has 10 digits {0,1,2,3,4,5,6,7,8,9} is called base-10 number system. The conversion between decimal (base-10) to 8-bit binary (base-2) is carried out by arithmetic modulus and division operators. The decimal to binary conversion returns 8-bit binary number result for any decimal value given between 0 to 255. for example, if given a decimal value is 19, return 8-bit binary result will be 00010011. for example, if given a decimal value is 83, return 8-bit binary result will be 01010011. Decimal to 8 bits binary conversion - algorithm Variable Declaration Input Read integer decval Output char bits[9] Temp var integer n,reminder     Loop decval not equal zero reminder = decval module by 2 bits[n] = reminder decval = decval divide by 2 n=n+1 End L...

Decimal to Binary Conversion

Image
The binary number consists of 0's and 1's such number system has only two distinct digits {0,1} is called base-2 number system or radix-2 number system. and The decimal number system consist of 0's to 9's has 10 distinct digits {0,1,2,3,4,5,6,7,8,9} is called base-10 number system or radix-10 number system. The decimal to binary conversion or base-2 number to base-10 number conversion is carried out by c programming code. The decimal number is to convert is read from user during the program execution. Decimal to Binary Conversion - Example Example decimal value =23 converts it into equivalent binary bits =? The decimal-value divide by 2 returns a quotient and a reminder, in which the quotient turns decimal-value to next round. This process repeated until quotient becomes 0 or 1. round Decimal divider quotient reminder 1 23 ...