Big to Little Endian
Description:
Your operating system screwed some things up. It has received some unsigned 32 bit integer from the Internet, but nobody told your OS about the "network byte order" and his "host byte order".
Your job is to write a function ntoh
which takes a 32 bit unsigned integer in the Big Endian byte order and returns the correct 32 bit unsigned integer in the Little Endian order.
To refresh your knowledge about byte order. One byte are 8 bits, so a 32 bit unsigned integer consists of 4 bytes which are ordered the wrong way.
If an integer longer than 32 bit is given the function has to raise a nasty exception.
Example:
* 42949695 => 1063030530
42949695
as a 32 bit integer is
00000010 10001111 01011100 00111111
which translates to
00111111 01011100 10001111 00000010
which is 1063030530
.
Similar Kata:
Stats:
Created | May 7, 2014 |
Published | May 7, 2014 |
Warriors Trained | 546 |
Total Skips | 361 |
Total Code Submissions | 741 |
Total Times Completed | 141 |
Ruby Completions | 131 |
COBOL Completions | 3 |
Total Stars | 10 |
% of votes with a positive feedback rating | 91% of 58 |
Total "Very Satisfied" Votes | 49 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 21 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |