Repository: vaskoz/dailycodingproblem-go (go)

Issue:
Day 161
Good morning! Here's your coding interview problem for today.

This problem was asked by Facebook.

Given a 32-bit integer, return the number with its bits reversed.

For example, given the binary number `1111 0000 1111 0000 1111 0000 1111 0000`, return `0000 1111 0000 1111 0000 1111 0000 1111`.

Pull request description:
Day161
Resolves #334.

Patch:
diff --git a/README.md b/README.md
index cb4b438..816f4f6 100644
--- a/README.md
+++ b/README.md
@@ -170,5 +170,6 @@ problems from
 * [Day 157](https://github.com/vaskoz/dailycodingproblem-go/issues/327)
 * [Day 158](https://github.com/vaskoz/dailycodingproblem-go/issues/329)
 * [Day 159](https://github.com/vaskoz/dailycodingproblem-go/issues/331)
+* [Day 161](https://github.com/vaskoz/dailycodingproblem-go/issues/334)
 * [Day 162](https://github.com/vaskoz/dailycodingproblem-go/issues/335)
 * [Day 163](https://github.com/vaskoz/dailycodingproblem-go/issues/336)
diff --git a/day161/problem.go b/day161/problem.go
new file mode 100644
index 0000000..ff1dfe0
--- /dev/null
+++ b/day161/problem.go
@@ -0,0 +1,17 @@
+package day161
+
+// Reverse32Bits reverses the bits and returned the result.
+// Runs in O(32) time.
+func Reverse32Bits(num uint32) uint32 {
+	var rev uint32
+	offset := uint(32)
+	for num != 0 {
+		offset--
+		rev <<= 1
+		if num&1 == 1 {
+			rev ^= 1
+		}
+		num >>= 1
+	}
+	return rev << offset
+}


Test patch:
diff --git a/day161/problem_test.go b/day161/problem_test.go
new file mode 100644
index 0000000..6a6614a
--- /dev/null
+++ b/day161/problem_test.go
@@ -0,0 +1,27 @@
+package day161
+
+import "testing"
+
+var testcases = []struct {
+	given, expected uint32
+}{
+	{4042322160, 252645135},
+	{3, 3221225472},
+}
+
+func TestReverse32Bits(t *testing.T) {
+	t.Parallel()
+	for _, tc := range testcases {
+		if result := Reverse32Bits(tc.given); result != tc.expected {
+			t.Errorf("Expected %v got %v", tc.expected, result)
+		}
+	}
+}
+
+func BenchmarkReverse32Bits(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testcases {
+			Reverse32Bits(tc.given)
+		}
+	}
+}