ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This is a quick question: is '%b' a valid conversion to use in any of the 'printf' routines for binary data? I did some searching through old posts in this site and found some that said it is, though internet searching outside this site, as well as books I've looked at (both recent and not so recent) don't seem to turn up that conclusion.
It's probably better to just write(STDOUT_FILENO, data, size);, making sure to fflush(stdout); before the binary output.
ta0kira
PS The option you'd be looking for, if it was available, would just be a size specification for %s since otherwise the data's size isn't known. %s prints verbatim up to the first null byte, so all you're really looking for is printing of said null bytes, in which case nothing exists to delimit the data.
PS What doesn't make sense is that strtol can have 35 bases and printf can only use 3.
Good point. Though for printf there are already 22 letters used as conversion specifiers, so 35 would be too much for printf. But certainly enough left some of the more useful ones...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.