Vee's Golang Notes

Lab Three

21 Sep 2025

Operators & Expressions (Go Version)

  1. Rewrite the following expression without using && and not by using conditional statements like if.
((i < limit-1 && (c = readChar()) != '\n') && c != 'A')

Hint: Apply De Morgan’s theorem:

  • not (A and B) is the same as (not A) or (not B)
  • not (A or B) is the same as (not A) and (not B)

  1. If x is 1 and y is 2 then x & y is zero while x && y is 1. Why?

  1. Write and test a function rotate.
    The function receives two integer arguments, the value to be rotated (s) and a count of the number of times to rotate (r).
    Having rotated the value in s it provides this result as its return value.
func rotate(s uint, r uint) uint

The function must rotate s to the left r times, shifting bits from the right (LSB) to the left (MSB).
The test program should prompt for values from the user, call rotate, and then output both the original value and the shifted value in hexadecimal.

Example:

input two values: 4 2
original: 4
rotated:  10

You should not use a loop in your implementation of rotate.
Ensure that your implementation is portable.


  1. Using a single for or for-while style statement (with an empty body) and comma-separated operations, write a program that displays 10 powers of 2.

Optional Questions

  1. Extend the noughts-and-crosses (tic-tac-toe) program to check for the end of the game (i.e., when any row, column, or diagonal is filled with either X or O) and report the result.

  1. Extend the noughts-and-crosses game so that a single user plays against the computer.
    You may develop this program gradually as the course progresses, adding refinements as they occur to you.