Binary operations in C
Implement a function that gets two 4-bit binary numbers, say a
and b, and returns a 16-bit integer value by performing several
bit-wise operations on them. The 16-bit number is formed as
follows:
the four leftmost bits hold the result of the AND operation
between the two binary numbers
the next four bits hold the result of the OR operation between
the two binary numbers
the next four bits hold the result of the XOR operation between
the two binary numbers
the last four bits hold the result of the NOT operation on the
binary number a.
For example, when the first number is a = 1111 and the second is
b = 1010, then result would be 1010111101010000, 0xAF50 in
hexadecimal and 44880 in decimal format.
TIPS:
\brief Forms a 16 bit integer value by performing several
bit-wise operations
* on two 4-bit arguments a and
b.
*
* \details This function has two arguments a and b, which
are both 4 bit long.
* It returns a 16-bit
number that is formed as follows:
* - the four leftmost
bits hold the result of the AND operation between
* the two binary
numbers (a AND b)
* - the next four bits
hold the result of the OR operation between
* the two binary
numbers (a OR b)
* - the next four bits
hold the result of the XOR operation between
* the two binary
numbers (a XOR b)
* - the last four bits
hold the result of the NOT operation on the
* binary number a
(NOT a).
* For example, given a =
1111 and b = 1010, then result would be
* 1010111101010000
(0xAF50 in hexadecimal and 44880 in decimal).
*
* \param a A four bit integer value, which always masked
with 0x0f
* \param b A four bit integer value, which always masked
with 0x0f
* \return The resultant 16-bit integer
*
* \note Remember to limit a's NOT operation to four bits
with
* bit mask: & 0xf.
*
* \note In your implementation, do not write to stdout to
check the functionality.
* You should use my_tests function to
print and check the functionality
* of your implementation.
*/
CODE TEMPLATE:
short combine_with_operations(unsigned char a, unsigned char b)
{
//IMPLEMENT CODE HERE//
return 0;
}
Binary operations in C Implement a function that gets two 4-bit binary numbers, say a and b, and returns a 16-bit integer value by performing several bit-wise operations on them. The 16-bit number is formed as follows: • the four leftmost bits hold the result of the AND operation between the two binary numbers • the next four bits hold the result of the or operation between the two binary numbers • the next four bits hold the result of the Xor operation between the two binary numbers • the last four bits hold the result of the Not operation on the binary number a. For example, when the first number is a = 1111 and the second is b = 1010, then result would be 1010111101010000, OxAF50 in hexadecimal and 44880 in decimal format. Hint Remember to limit a 's NOT operation to four bits with bit mask: & exf.
Binary operations in C Implement a function that gets two 4-bit binary numbers, say a and b, and returns a 16-bit intege
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am