
ECE201 Lab#7: Bitwise Operations and Numerical Conversions
Put the instructions in a script file (with .m extension) for this lab.
Part A: Write an M-File Function that will:
•receive in an 8-bit binary ’number’ as its only input and call it EightBitWord.
Note: the input must be a string or MATLAB will return an error.
•return an error if (1) more than eight characters are entered, or (2) if a character other
than a 0 or a 1 is entered. Re-enter it if this occurs.
•pad any input less than 8 bits long with 00sto make it 8 bits long without changing its
value.
•output the input’s decimal equivalent, call it DecValue, and display.
•convert DecValue to its hexadecimal equivalent, call it HexValue and display.
•output the input’s decimal equivalent after being shifted 2 to the right and call it Shift2R.
Part B: Write an M-File Function that will:
•call as inputs DecValue, and Shift2R from Part A.
•AND DecValue with 29 and call this value ANDwith29.
•set the sixth bit in Shift2R to 1 and call this value Setin6.
•convert Setin6 to its binary equivalent and call BIN1.
•convert ANDwith29 to its binary equivalent and call BIN2.
•output a 16-bit word called BIN16 with BIN1 as the MSB and BIN2 the LSB.
•convert BIN16 to its decimal equivalent, call it DECofBIN16 and display.
•compliment BIN16 call it COMPofBIN16 and display.
•if COMPofBIN16 is greater than 65535, reset to 65535.
•output the hexadecimal conversion of BIN16 and call it HEX4A.
•output the hexadecimal conversion of COMPofBIN16 and call it HEX4B
•display all outputs.
Document your activities and results in a typed report. Include your MATLAB code and your
plots.
1