class WoolenCommon::TypeHelper

Public Class Methods

get_high_bit_num(number,all_bits,high_start_bits) click to toggle source
# File lib/woolen_common/type_helper.rb, line 23
def get_high_bit_num(number,all_bits,high_start_bits)
    bits_mask = 0
    (high_start_bits..all_bits-1).each do |step_bit|
        bits_mask += (1 << (step_bit))
    end
    number & bits_mask
end
get_low_bit_num(number,hight_start_bits) click to toggle source
# File lib/woolen_common/type_helper.rb, line 32
def get_low_bit_num(number,hight_start_bits)
    bits_mask = 0
    (0..hight_start_bits-1).each do |step_bit|
        bits_mask += (1 << (step_bit))
    end
    number & bits_mask
end
to_signed(number, bits) click to toggle source
# File lib/woolen_common/type_helper.rb, line 6
def to_signed(number, bits)
    mask = (1 << (bits - 1))
    (number & ~mask) - (number & mask)
end
to_unsigned(number, bits) click to toggle source
# File lib/woolen_common/type_helper.rb, line 11
def to_unsigned(number, bits)
    mask_high = (1 << (bits - 1))
    mask_low = 0
    (bits-1).times do |step_bit|
        mask_low += (1 << (step_bit))
    end
    high = number & mask_high
    low = number & mask_low
    #debug "to unsigned #{high},#{low}"
    high + low
end