开发者

Print a number in base 4

开发者 https://www.devze.com 2023-02-19 08:58 出处:网络
Lately I had a 开发者_如何学JAVAtask that included printing base-4 representation of a number. Since I didn\'t find a function to do it for me, I implemented it (which is not so hard of course), but I

Lately I had a 开发者_如何学JAVAtask that included printing base-4 representation of a number. Since I didn't find a function to do it for me, I implemented it (which is not so hard of course), but I wonder, is there a way to do it using format placeholders?

I'm not asking how to implement such function, but if such function / format placeholder already exists?


There is no standard C or C++ function, but you may be able to use itoa


The closest you could get to doing it with printf is using snprintf to convert it to hex, then a lookup table to convert hex digits to pairs of base-4 digits. :-)


No, not in the Standard C library.


I think that printf can handle only decimal, hexadecimal and octal values. So i think no.

0

精彩评论

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