# radix-sort with different bases

So i understand how to use radix-sort in base 10 and utilize mod 10 to go through the numbers. But not sure about 2,8 or 16.

Does it follow the same idea? and i read somewhere that i need to pass the base number to the radix function but not sure why would that be needed? because if i have for example:

int arr[] = {0xAA, 0x2D , 0x4B, 0x5A, 0x322, 0x24, 0x2, 0x42};


it works perfectly. So not sure why i need to pass the base to the function.

## 1 Answer

Radix sort splits data into own digits of given size, you may choose the base in which data would be treated. If you have 64bit integer you may choose size of radix to be any number, say 2 bits, 4bits, 21bits, 32bits etc., but since computer stores digits as binary numbers it makes more sense to stick with power of two.
Also, you would like to omit modulo operator and use bit masks for efficiency purposes, which is not possible for other numbers.

You haven't described your code, but if it assumes 10 as default base, it is perfectly good, your code is in hexadecimal representation, which gets stored as binary and then treated as decimal based number for sorting. This doesn't change your code, just language feature to provide numbers like that (you can input octal number using 0 in front, say 056, but it will not change running time, but changing radix will).

• So if we assume this code example, geeksforgeeks.org/radix-sort . Would the size of count array be the base number? its now 10 but if its switched to 16 then its in hexadecimal? – CODINGNONSTOPSON Apr 24 '19 at 23:39
• Yes, but you have to change much more to get radix 16 in this code. – Evil Apr 25 '19 at 6:32