pub fn sext(i: u16, msb_pos: u8) -> u16 {
    let mut digit = 0;
    let n = (1 << msb_pos & i) >> msb_pos;
    let num_iter = 16 - 1 - msb_pos;
    for j in 0..num_iter {
        let old = n << (j + msb_pos + 1);
        digit += old;
    }
    digit + i
}
// sign extends i to 16 bits using the digit at msb_pos
sign extends i to 16 bits using the digit at msb_pos
sign extends i to 16 bits using the digit at msb_pos
pub fn sext(i: u16, msb_pos: u8) -> u16 {
    let mut digit = 0;
    let n = (1 << msb_pos & i) >> msb_pos;
    let num_iter = 16 - 1 - msb_pos;
    for j in 0..num_iter {
        let old = n << (j + msb_pos + 1);
        digit += old;
    }
    digit + i
}
pub fn sext ( i : u16 , msb_pos : u8 ) -> u16 { let mut digit = 0 ; let n = ( 1 << msb_pos & i ) >> msb_pos ; let num_iter = 16 - 1 - msb_pos ; for j in 0 .. num_iter { let old = n << ( j + msb_pos + 1 ) ; digit += old ; } digit + i }
sign extends i to 16 bits using the digit at msb_pos
sign extends i to 16 bits using the digit at msb_pos
i
u16
msb_pos
u8
i
u16
msb_pos
u8