In: Computer Science
Please provide computation for each conversion and Don't use large/big values. Thank you!
Give a value for each number system (decimal, binary, octal and hexa-decimal) then convert each value to each number system (example: given value is decimal, convert the given value to binary, octal and hexa-decimal and vice-versa).
Conversion methodologies (along with the examples) below:
Decimal to Binary
Divide the given decimal number by 2. Keep the remainder for the binary digit. Calculate the integer quotient for the next iteration. Keep doing this until the quotient is 0.
Example:
Converting 500 (in decimal) to binary:
The left column represents the number that is used as a divisor. The red digits are the remainders except the last one which is the quotient.
The final binary number is to be read from downwards (as per the arrow represented above).
500 -> 111110100
Binary to decimal
Converting the above number back to decimal:
Row A - this is the binary number that needs to be converted
Row B - this needs to be set starting with the right most bit. set this at 2^0 and the moving to the left increasing the power by 1.
Finally to get to the decimal number by multiply A by B:
2^8 * 1 + 2^7 * 1 + 2^6 * 1 + 2^5 * 1 + 2^4 * 1 + 2^3 * 0 + 2^2 * 1 + 2^1 * 0 + 2^0 * 0 = 500
Decimal to Octal
Divide the given decimal number by 8. Keep the remainder for the octal digit. Calculate the integer quotient for the next iteration. Keep doing this until the quotient is 0.
Example:
Converting 500 (in decimal) to octal:
The left column represents the number that is used as a divisor. The red digits are the remainders except the last one which is the quotient.
The final octal number is to be read from downwards (as per the arrow represented above).
500 -> 764
Octal to decimal
Converting the above number back to decimal:
Row A - this is the octal number that needs to be converted
Row B - this needs to be set starting with the right most bit. set this at 8^0 and the moving to the left increasing the power by 1.
Finally to get to the decimal number by multiply A by B:
8^2 * 7 + 8^1 * 6 + 8^0 * 4 = 500
Decimal to Hexa-decimal
Divide the given decimal number by 16. Keep the remainder for the hexa-decimal digit. Calculate the integer quotient for the next iteration. Keep doing this until the quotient is 0.
Example:
Converting 500 (in decimal) to hexa-decimal:
The left column represents the number that is used as a divisor. The red digits are the remainders except the last one which is the quotient.
The final hexa-decimal number is to be read from downwards (as per the arrow represented above).
500 -> 1 15 4
However, for hexa-decimal, the representation is as below:
As a result, the above digit 15 will be represented as F.
Final hexa-decimal value - 1F4
Hexa-decimal to decimal
Converting the above number back to decimal:
Row A - this is the hexa-decimal number that needs to be converted
Row B - this needs to be set starting with the right most bit. set this at 16^0 and the moving to the left increasing the power by 1.
Finally to get to the decimal number by multiply A by B:
16^2 * 1 + 16^1 * 15 (value of F i.e. 15) + 16^0 * 4 = 500
Let me know if anything is not clear.