Search code examples
radix-sort

Breaking a 32 bit integer into 8 bit chucks for Radix Sort


I am basically a beginner in Computer Science. Please forgive me if I ask elementary questions. I am trying to understand radix sort. I read that a 32 bit unsigned integer can be broken down into 4 8-bit chunks. After that, all it takes is "4 passes" to complete the radix sort. Can somebody please show me an example for how this breakdown (32 bit into 4 8-bit chunks) works? Maybe, a 32-bit integer like 2147507648.

Thanks!


Solution

  • It's done as follows:

       2147507648
    => 0x80005DC0 (hex value of 2147507648)
    => 0x80 0x00 0x5D 0xC0
    => 128  0    93   192
    

    To do this, you'd need bitwise operations as nos suggested.