diff --git a/src/simulation/compile.cpp b/src/simulation/compile.cpp
index 1f93b921b4000b3c776284714cbe9a07e49fc504..7fa7ac6721c9af0f5b9decdf8c3f0dca653e47ec 100644
--- a/src/simulation/compile.cpp
+++ b/src/simulation/compile.cpp
@@ -204,8 +204,8 @@ private:
 			if (bits > 64) {
 				throw py::value_error{"Cannot truncate to more than 64 bits"};
 			}
-			this->add_instruction(instruction_type::truncate, no_result_index, 0).bit_mask = static_cast<std::int64_t>(std::int64_t{1}
-																													   << bits);
+			this->add_instruction(instruction_type::truncate, no_result_index, 0).bit_mask = static_cast<std::int64_t>(
+				(std::int64_t{1} << bits) - 1);
 		}
 	}
 
diff --git a/src/simulation/run.cpp b/src/simulation/run.cpp
index 1f27b0c70e4d70ec057953caded37a4f40ab1b10..c14fa192bf0fd52a6b661aa4fb392b78859c382f 100644
--- a/src/simulation/run.cpp
+++ b/src/simulation/run.cpp
@@ -31,7 +31,7 @@ namespace asic {
 		if (*bits_override > 64) {
 			throw py::value_error{"Cannot truncate to more than 64 bits"};
 		}
-		return static_cast<std::int64_t>(std::int64_t{1} << *bits_override); // Return the bit mask override to use.
+		return static_cast<std::int64_t>((std::int64_t{1} << *bits_override) - 1); // Return the bit mask override to use.
 	}
 	bits_override.reset(); // Don't use bits_override if truncate is false.
 	return std::int64_t{};
diff --git a/test/test_fast_simulation.py b/test/test_fast_simulation.py
index 6eb3b251bec6a2c556230dbedcb8f712c9f56d48..acdea48d2bf51040b59fda5bd99d67ed158a1035 100644
--- a/test/test_fast_simulation.py
+++ b/test/test_fast_simulation.py
@@ -122,6 +122,12 @@ class TestRunFor:
         assert simulation.results["0"][4] == -6
         assert simulation.results["0"][5] == 7
 
+    def test_find_result_key(self, precedence_sfg_delays):
+        sim = FastSimulation(precedence_sfg_delays, [[0, 4, 542, 42, 31.314, 534.123, -453415, 5431]])
+        sim.run()
+        assert sim.results[precedence_sfg_delays.find_result_keys_by_name("ADD2")[0]][4] == 31220
+        assert sim.results[precedence_sfg_delays.find_result_keys_by_name("A1")[0]][2] == 80
+
 class TestRun:
     def test_save_results(self, sfg_two_inputs_two_outputs):
         simulation = FastSimulation(sfg_two_inputs_two_outputs, [2, 3])