vb.net - What is the fastest way to retrieve at runtime big powers of two in decimal string format? -
in order display big numbers need able retrieve powers of 2 in decimal string format. following code best do, there faster way?
public notinheritable class twopowerof private decimalstring string = "" public sub new(byval myinteger integer) if myinteger > -256 , myinteger < 1024 me.decimalstring = gettwopowerof(myinteger) end if end sub public overrides function tostring() string return me.decimalstring end function protected function gettwopowerof(byval myinteger integer) string dim result string = "" dim d new dictionary(of integer, string) '... d.add(2, "4") d.add(1, "2") d.add(0, "1") d.add(-1, "0.5") d.add(-2, "0.25") d.add(-3, "0.125") d.add(-4, "0.0625") d.add(-5, "0.03125") d.add(-6, "0.015625") d.add(-7, "0.0078125") d.add(-8, "0.00390625") ' ... result = d.item(myinteger) return result end function end class
and retreiving this:
sub whatever() dim myinteger integer dim mydecimalstring string = new twopowerof(myinteger).tostring console.writeline(mydecimalstring) end sub
or, there way convert big binary numbers decimals without using powers of two?
Comments
Post a Comment