开发者

Conversion of binary to octal or hex. Which one is easy (C language compiler)

I was going through some questions related to C programming language. An开发者_C百科d i found this question to be confusing. http://www.indiabix.com/c-programming/bitwise-operators/discussion-495

The question is "is it easy for a c compiler to convert binary to hexadecimal or binary to octal. The explanation given there is group every 4 bits and convert it to hex.. but its very easy to group 3 bits and convert it to octal. or is it easy for a human to convert octal easily than hex?

what would be the easiest method of a compiler to convert binary to octal/hex


All of them are the same in easiness. However, in computing world the use of octal is kinda seldom compared to hex. The only quite important use is on unix style permissions, other than that it's hex and binary that takes the lead (along with decimal for common human friendly style).


Both octal and hexadecimal can be converted from binary by grouping the bits(3 in case of octal and 4 in case of hexadecimal) http://www.ascii.cl/conversion.htm

But the thing is that the memory allocate by compiler is in 2^n and you can't split 2^n 3 size blocks while it can be done easily with hexadecimal where block size is 4

for example with gcc concider integer of 32 bits which can't be split into equal 3 bit 32/3 = 10.666 while it can be split in to 4 bits block 32/4 = 8

Hope I make my point clear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜