Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

to-octal function

    to-octal: func [
        "Converts an integer to an octal issue!."
        value [integer!] "Value to be converted"
        /width wd
        /local result pad
    ][
        pad: func [val wd] [head insert/dup val #"0" wd - length? val]
        result: copy #   ; empty issue!
        if 0 = value [return pad result any [wd 1]]
        while [0 <> value] [
            insert result value // 8
            value: round/down value / 8
        ]
        pad result any [wd 1]
    ]

from-octal

    from-octal: func [
        "Converts an octal number to a decimal value."
        octal [any-string! integer!]
        /local result len
    ][
        result: 0
        octal: form octal
        repeat i len: length? octal [
            result: add result (to integer! form octal/:i) * (8 ** (len - i))
        ]
        any [attempt [to integer! result] result]
    ]

Generic base conversor //Javascript Object


Minimum Common Multiple

[UPDATED CODE AND HELP CAN BE FOUND HERE]


//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/number/base-conversor [v1.0]

Conversor = {
	h: '0123456789abcdefghijklmnopqrstuvwxyz',

	int2base: function( n, base ){
		if( base < 2 || base > this.h.length )
			throw new Error( "base inválida" );
		for( var n = parseInt( n ) || 0, result = ""; n; result = this.h.charAt( n % base ) + result, n = Math.floor( n / base ) );
		return result;
	},
	base2int: function( s, base ){
		for( var i = -1, l = s.length, result = 0; ++i < l; result = result * base + this.h.indexOf( s.charAt( i ) ) );
		return result;
	}
}
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS