#Output bytes of int

1 messages · Page 1 of 1 (latest)

sterile crypt
#

I currently have this:

const int = std.fmt.parseInt(i64, str, 10);
try dest.writeAll([]u8{
  0x01,
                 int and 0xFF,
  @shrExact(int, 8)  and 0xFF,
  @shrExact(int, 16) and 0xFF,
  @shrExact(int, 24) and 0xFF,
  @shrExact(int, 32) and 0xFF,
  @shrExact(int, 40) and 0xFF,
  @shrExact(int, 48) and 0xFF,
  @shrExact(int, 56) and 0xFF,
});

but I am sure that there is a better way to do this (if this even works)

#

wait

#

I could just take the pointer to that and reinterpret cast that as byte pointer

woeful turtle
#

try dest.writeInt(i64, int, .little);

sterile crypt
#

and print that as array of length 8

sterile crypt
#

thanks!

woeful turtle
#

also I'm not sure what you think @shrExact does, but it would crash if used here

woeful turtle
#

int >> 8

sterile crypt
#

oh

#

uh

#

thanks

#

and how do I do that for IEEE 754 floats?

#

same thing but with @bitCast maybe?

woeful turtle
#

yep, try dest.writeInt(u32, @bitCast(float), .little);