LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2008, 01:40 PM   #1
cleopard
Member
 
Registered: May 2006
Posts: 39

Rep: Reputation: 15
binary for 'printf' routines


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.
 
Old 08-21-2008, 01:59 PM   #2
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
i don't think so
the man pages doesn't mention it and "gcc -Wall" says:
warning: unknown conversion type character ‘b’ in format

look in "man 3 printf"
all the options should be there.
 
Old 08-21-2008, 04:34 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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.

Last edited by ta0kira; 08-21-2008 at 04:38 PM.
 
Old 08-21-2008, 07:04 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I may be wrong, but I thought the OP was asking for a format specifier to output things like: 11010101
 
Old 08-21-2008, 09:23 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
That would make a lot more sense.
ta0kira

PS What doesn't make sense is that strtol can have 35 bases and printf can only use 3.

Last edited by ta0kira; 08-21-2008 at 09:32 PM.
 
Old 08-22-2008, 05:32 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by ta0kira View Post
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...
 
Old 08-22-2008, 07:36 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I was thinking something more along the lines of %^2b to specify e.g. base-2.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User Copy Routines vduvvuru Linux - Kernel 3 03-05-2008 06:27 PM
Elan520 Interrupt Routines MattFunke Programming 0 11-02-2007 01:13 PM
Too many startup routines? Keithj Fedora 2 07-20-2007 08:03 PM
IDE Routines ashlesha Linux - Software 0 08-09-2006 12:29 PM
ARP routines.... shrishailnk Linux - Networking 2 04-29-2006 11:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration