mirror of
https://codeberg.org/ziglings/exercises.git
synced 2025-06-05 23:34:47 +00:00
Changed the values for better understanding
This commit is contained in:
parent
377d184cdc
commit
761fb1a501
@ -1146,7 +1146,7 @@ const exercises = [_]Exercise{
|
|||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.main_file = "097_bit_manipulation.zig",
|
.main_file = "097_bit_manipulation.zig",
|
||||||
.output = "x = 0; y = 1",
|
.output = "x = 1011; y = 1101",
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.main_file = "098_bit_manipulation2.zig",
|
.main_file = "098_bit_manipulation2.zig",
|
||||||
|
@ -71,9 +71,9 @@ const print = std.debug.print;
|
|||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
||||||
// As in the example above, we use 1 and 0 as values for x and y
|
// Let us use 1101 and 1011 as values for x and y
|
||||||
var x: u8 = 1;
|
var x: u8 = 0b1101;
|
||||||
var y: u8 = 0;
|
var y: u8 = 0b1011;
|
||||||
|
|
||||||
// Now we swap the values of the two variables by doing xor on them
|
// Now we swap the values of the two variables by doing xor on them
|
||||||
x ^= y;
|
x ^= y;
|
||||||
@ -82,7 +82,7 @@ pub fn main() !void {
|
|||||||
// What must be written here?
|
// What must be written here?
|
||||||
???;
|
???;
|
||||||
|
|
||||||
print("x = {d}; y = {d}\n", .{ x, y });
|
print("x = {b}; y = {b}\n", .{ x, y });
|
||||||
}
|
}
|
||||||
|
|
||||||
// This variable swap takes advantage of the fact that the value resulting
|
// This variable swap takes advantage of the fact that the value resulting
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--- exercises/097_bit_manipulation.zig 2023-10-03 22:15:22.125574535 +0200
|
--- exercises/097_bit_manipulation.zig 2025-05-12 21:25:03.395385743 +0200
|
||||||
+++ answers/097_bit_manipulation.zig 2023-10-05 20:04:07.282771124 +0200
|
+++ answers/097_bit_manipulation.zig 2025-05-12 21:22:57.472986976 +0200
|
||||||
@@ -80,7 +80,7 @@
|
@@ -80,7 +80,7 @@
|
||||||
y ^= x;
|
y ^= x;
|
||||||
|
|
||||||
@ -7,5 +7,5 @@
|
|||||||
- ???;
|
- ???;
|
||||||
+ x ^= y;
|
+ x ^= y;
|
||||||
|
|
||||||
print("x = {d}; y = {d}\n", .{ x, y });
|
print("x = {b}; y = {b}\n", .{ x, y });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user