/// Converts value into i64 type using 2C representation.
/// # Example
/// ```
/// use interp::values::*;
/// let signed_neg_1_4 = (Value::try_from_init(15, 4).unwrap()).as_i64();
/// assert_eq!(signed_neg_1_4, -1);
/// ```
Converts value into i64 type using 2C representation.
Converts value into i64 type using 2C representation .
pub fn as_i64(&self) -> i64 {
        let vec_len = self.vec.len() as u32;
        if vec_len == 0 {
            return 0;
        }
        let pow_base = -2;
        let msb_weight = i64::pow(pow_base, vec_len - 1);
        let mut tr: i64 = 0;
        let iter = self.vec.iter().by_ref();
        //which way will it iterate? Hopefully w/ LsB = 0
        for (place, b) in iter.enumerate() {
            if *b {
                if place >= (vec_len - 1) as usize {
                    //2s complement, so MSB has negative weight
                    //this is the last place
                    tr += msb_weight;
                } else {
                    //before MSB, increase as unsigned bitnum
                    tr += i64::pow(2, place as u32); //
                }
            }
        }
        tr
    }
pub fn as_i64 ( & self ) -> i64 { let vec_len = self . vec . len ( ) as u32 ; if vec_len == 0 { return 0 ; } let pow_base = - 2 ; let msb_weight = i64 :: pow ( pow_base , vec_len - 1 ) ; let mut tr : i64 = 0 ; let iter = self . vec . iter ( ) . by_ref ( ) ; //which way will it iterate? Hopefully w/ LsB = 0 for ( place , b ) in iter . enumerate ( ) { if * b { if place >= ( vec_len - 1 ) as usize { //2s complement, so MSB has negative weight //this is the last place tr += msb_weight ; } else { //before MSB, increase as unsigned bitnum tr += i64 :: pow ( 2 , place as u32 ) ; // } } } tr }
Converts value into i64 type using 2C representation.
Converts value into i64 type using 2C representation .
&self
example
None