I was messing around with this, but I tried to generalize this method so it could be applied to any numeral system. So from binary to binary coded <numeral system>. However so far I have only been able to get it working for all the numeral systems with even base numbers:
The amount of bits to represent each digit equals: ceil(log2(base))
Edge from which you have to add a certain number to the value before shifting equals: base / 2
This is also way it only works for even base numbers.
The certain number which has to be conditionally added to the value equals: 2^(amount of bits - 1) - egde
So in terms of the base value: 2^(floor(log2(base))) - base / 2
For example base-12:
amount of bits per digit = ceil(log2(12)) = 4 (same amount as BCD)
Edge = 12 / 2 = 6
Add = 2^(floor(log2(12)) - 12 / 2 = 2
Lets start with the binary value 10100111001 (which equals 1337 in decimal)
0000 0000 0000 10100111001 start
0000 0000 0001 01001110010 First shift
0000 0000 0010 10011100100 Second shift
0000 0000 0101 00111001000 Third shift
0000 0000 1010 01110010000 Fourth shift
0000 0000 1100 01110010000 First digit is 6 or higher, add 2 before shifting.
0000 0001 1000 11100100000 Fifth shift
0000 0001 1010 11100100000 First digit is 6 or higher, add 2 before shifting.
0000 0011 0101 11001000000 Sixth shift
0000 0110 1011 10010000000 Seventh shift
0000 1000 1101 10010000000 First and second digit are 6 or higher, add 2 before shifting.
0001 0001 1011 00100000000 Eighth shift
0001 0001 1101 00100000000 First digit is 6 or higher, add 2 before shifting.
0010 0011 1010 01000000000 Ninth shift
0010 0011 1100 01000000000 First digit is 6 or higher, add 2 before shifting.
0100 0111 1000 10000000000 Tenth shift
0100 1001 1010 10000000000 First and second digit are 6 or higher, add 2 before shifting.
1001 0011 0101 00000000000 Eleventh shift
So 935 in base-12 should equal 1337 base-10 (or 10100111001 base-2)
Lets test this: 935 base-12 = 9 * 12^2 + 3 * 12^1 + 5 * 12^0 = 9 * 144 + 3 * 12 + 5 = 1337
By the way I was thinking about writing about this method on the ORE wiki, however all the current info is posted into one long page. Maybe we should restructurize this and divide into more manageable pages?
The amount of bits to represent each digit equals: ceil(log2(base))
Edge from which you have to add a certain number to the value before shifting equals: base / 2
This is also way it only works for even base numbers.
The certain number which has to be conditionally added to the value equals: 2^(amount of bits - 1) - egde
So in terms of the base value: 2^(floor(log2(base))) - base / 2
For example base-12:
amount of bits per digit = ceil(log2(12)) = 4 (same amount as BCD)
Edge = 12 / 2 = 6
Add = 2^(floor(log2(12)) - 12 / 2 = 2
Lets start with the binary value 10100111001 (which equals 1337 in decimal)
0000 0000 0000 10100111001 start
0000 0000 0001 01001110010 First shift
0000 0000 0010 10011100100 Second shift
0000 0000 0101 00111001000 Third shift
0000 0000 1010 01110010000 Fourth shift
0000 0000 1100 01110010000 First digit is 6 or higher, add 2 before shifting.
0000 0001 1000 11100100000 Fifth shift
0000 0001 1010 11100100000 First digit is 6 or higher, add 2 before shifting.
0000 0011 0101 11001000000 Sixth shift
0000 0110 1011 10010000000 Seventh shift
0000 1000 1101 10010000000 First and second digit are 6 or higher, add 2 before shifting.
0001 0001 1011 00100000000 Eighth shift
0001 0001 1101 00100000000 First digit is 6 or higher, add 2 before shifting.
0010 0011 1010 01000000000 Ninth shift
0010 0011 1100 01000000000 First digit is 6 or higher, add 2 before shifting.
0100 0111 1000 10000000000 Tenth shift
0100 1001 1010 10000000000 First and second digit are 6 or higher, add 2 before shifting.
1001 0011 0101 00000000000 Eleventh shift
So 935 in base-12 should equal 1337 base-10 (or 10100111001 base-2)
Lets test this: 935 base-12 = 9 * 12^2 + 3 * 12^1 + 5 * 12^0 = 9 * 144 + 3 * 12 + 5 = 1337
By the way I was thinking about writing about this method on the ORE wiki, however all the current info is posted into one long page. Maybe we should restructurize this and divide into more manageable pages?