Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/compiler/progs/bitrev.osc # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / compiler / progs / bitrev.osc` 26 lines ยท 613 bytes Raw Blame History 1 // entry: rev8 rev16 rev16_twice 2 // expect-run: rev8 1 -> 128 3 // expect-run: rev8 6 -> 96 4 // expect-run: rev16 1 -> 32768 5 // expect-run: rev16 4660 -> 11336 6 // expect-run: rev16_twice 513 -> 1 7 // bit reversal for u8 and u16. 8 fn rev8(x: u8) -> u8 { 9 let mut r: u8 = 0; 10 let mut v: u8 = x; 11 for i in 0 .. 8 { 12 r = (r << 1) | (v & 1); 13 v = v >> 1; 14 } 15 return r; 16 } 17 18 fn rev16(x: u16) -> u16 { 19 let lo: u8 = (x & 0xff) as u8; 20 let hi: u8 = (x >> 8) as u8; 21 return ((rev8(lo) as u16) << 8) | (rev8(hi) as u16); 22 } 23 24 fn rev16_twice(x: u16) -> bool { 25 return rev16(rev16(x)) == x; 26 }