In this recipe, we will learn how to convert a decimal number into a binary number by masking certain bits of a register. Masking means isolating or separating out the desired binary digits. Masking hides the undesired binary digits and makes only the desired binary digits visible.
Converting a decimal number into binary using bit masking
How to do it…
To convert a decimal number into a binary number using bit masking, perform the following steps:
- Enter a decimal value. The decimal number entered is internally stored in the form of binary digits.
- Assign a number 1 followed by 31 zeros to a variable called mask.
- Mask each of the binary digits of the decimal number one by one, beginning from the...