mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-09 11:40:46 -05:00
mention builtin ex coming up
This commit is contained in:
parent
cc269968ea
commit
0f28e58eea
3 changed files with 10 additions and 2 deletions
|
@ -25,6 +25,9 @@ pub fn main() void {
|
|||
//
|
||||
// See if you can figure out the missing piece:
|
||||
for (bits) |bit, ???| {
|
||||
// Note that we convert the usize i to a u32 with
|
||||
// @intCast(), a builtin function just like @import().
|
||||
// We'll learn about these properly in a later exercise.
|
||||
var place_value = std.math.pow(u32, 2, @intCast(u32, i));
|
||||
value += place_value * bit;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
//
|
||||
// const Stuff = enum(u8){ foo = 16 };
|
||||
//
|
||||
// You can get the integer out with a built-in function:
|
||||
// You can get the integer out with a builtin function,
|
||||
// @enumToInt(). We'll learn about builtins properly in a later
|
||||
// exercise.
|
||||
//
|
||||
// var my_stuff: u8 = @enumToInt(Stuff.foo);
|
||||
//
|
||||
|
|
|
@ -419,7 +419,10 @@ pub fn main() void {
|
|||
// we need to loop through the items in reverse, skipping nulls, until
|
||||
// we reach the destination at the front of the array.
|
||||
fn printTrip(trip: []?TripItem) void {
|
||||
var i: u8 = @intCast(u8, trip.len); // convert usize length
|
||||
// We convert the usize length to a u8 with @intCast(), a
|
||||
// builtin function just like @import(). We'll learn about
|
||||
// these properly in a later exercise.
|
||||
var i: u8 = @intCast(u8, trip.len);
|
||||
|
||||
while (i > 0) {
|
||||
i -= 1;
|
||||
|
|
Loading…
Reference in a new issue