开发者

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

开发者 https://www.devze.com 2023-04-07 03:18 出处:网络
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

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

精彩评论

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