Posts

Showing posts with the label decimal to binary

Decimal to Binary Conversion - Bitwise Right shift Operator

It is a number system conversion from decimal value into binary bits is carried out using bitwise >> (right-shift) operator. The Right shift operator moves the bit position of a integer towards right direction. it removes bits from LSB (least significant bit) and add bits (0s) into MSB (most significant bit) and the number bits to remove and to add depends on a operand value next to the right shift operator. For example, the integer variable x=10 , move 1 bit using right-shift binary 8-bits x = 00001010 x = x >> 1 move 1 bit (remove one bit from LSB (0) and add one bit (0) into MSB binary 8-bits x = 00000101 and x's decimal value becomes 5. Decimal to binary conversion using Bitwise Right-shif...

Decimal to Binary Conversion - Bitwise Left shift operator

It is a number system conversion from decimal to binary, which is implemented by bitwise left shift operator. The left-shift operator shifts the bits of the decimal value towards left direction. it removes MSB bits and adds bits 0s on LSB of the decimal value. Decimal to Binary Conversion by Left-shift -Manual calculation Given decimal value =19, converts into binary bits. on each iteration, AND (bitwise operation ) with the decimal value and 128, if condition is true, returns 1, otherwise 0, the decimal left shift by 1 , resultant value stored on the same decimal value.  n (decval AND 128) Operation    Decval = decval << by 1 0 bit[0] = (19 AND 128) ? 1:0   38 = 19 <<1 1 bit[1] = (38 AND 128) ? 1:0   76 = 38 <<1 2 bit[2] = (78 AND 128) ? 1:0   152 = 38 <<1 3 bit[3] =...

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 ...