Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The rules for completing lab include: All of these problems can be done with the eight operators: ! ~ & ^ | + < <

The rules for completing lab include:

All of these problems can be done with the eight operators:

! ~ & ^ | + << >>

and some require you to stick with just a subset of these.

You are also limited to constants with length at most 8-bits

i.e. you are limited to constants with two hexadecimal digits.

You must use straight-line code no loops or conditionals.

Each puzzle also has a rating of 1 (easiest) to 4 (hardest).

There is a limit on the number of operations you may use (just to eliminate brute force solutions).

Each puzzle is worth 5 points

The Assignment

Puzzle One bitAnd - The goal is to implement the bitwise & operator using just the operators ~ and |.

You can test out your code by comparing the value returned by the & operator to the value returned by your function.

Difficulty Rating - 1

Legal Operators: ~ |

Max Ops: 8

int bitAnd(int x, int y) {}

Puzzle Two minusOne - Your function should return the value -1.

Difficulty Rating - 1

Legal Operators: ! ~ & ^ | + << >>

Max ops: 4

int minusOne() {}

Puzzle Three bitXor - x^y using only ~ and &

Difficulty Rating - 2

Example: bitXor(4, 5) = 1

Legal ops: ~ &

Max ops: 15

int bitXor(int x, int y) { }

Puzzle Four isTmax returns 1 if x is the maximum, two's complement number, and 0 otherwise

Difficulty Rating 2

Legal ops: ! ~ & ^ | + << >>

Max ops: 10

int isTmax(int x) { }

Puzzle Five allEvenBits - return 1 if all even-numbered bits in word set to 1

Examples: allEvenBits(0xFFFFFFFE) = 0, allEvenBits(0x55555555) = 1

Legal ops: ! ~ & ^ | + << >>

Max ops: 12

Rating: 2

int allEvenBits(int x) { }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

Students also viewed these Databases questions