-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpq.rs
40 lines (33 loc) · 1.07 KB
/
mpq.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::fs::File;
use std::io::Read;
use std::ptr::copy_nonoverlapping;
// Result:
// 11011010100010101000001001101
// 1101101010001
fn sp(){
let bytes: [u8; 4] = [77, 80, 81, 27];
let buf_a: [u8; 2] = [77, 80];
let buf_b: [u8; 2] = [81, 27];
let mut num_a: u32 = 0;
let mut num_b: u32 = 0;
unsafe {
copy_nonoverlapping(buf_a.as_ptr(), &mut num_a as *mut u32 as *mut u8, 2);
copy_nonoverlapping(buf_b.as_ptr(), &mut num_b as *mut u32 as *mut u8, 2);
}
println!("SP Bits: {:16b} {:16b}", num_a.to_le(), num_b.to_le());
}
fn main() {
sp();
let mut f: File = File::open("test.replay").unwrap();
let mut buf = [0u8; 4];
let size = f.read(&mut buf).unwrap();
let mut data: u32 = 0;
unsafe {
copy_nonoverlapping(buf.as_ptr(), &mut data as *mut u32 as *mut u8, 4)
}
let bits = data.to_le();
let _string = std::str::from_utf8(&buf).unwrap().to_owned();
println!("String: {:?} ", _string );
println!("Bytes: {:?} Size: {:?}", buf, size);
println!("U32: {:?} Bits: {:b}", bits, bits );
}