Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Writing single bits to a file

Thread view: 
riva - 27 Oct 2007 18:31 GMT
Normally we write to files in the form of characters.
Is there any way so that we can write data to the file in the form
single bits like five `0's and then six `1's etc.
Knute Johnson - 27 Oct 2007 18:57 GMT
> Normally we write to files in the form of characters.
> Is there any way so that we can write data to the file in the form
> single bits like five `0's and then six `1's etc.

Yes but you will have to write them in groups of 8.  But why would you
want to do this?  Do you need to write trillions of bits?  Why not just
use some simple scheme to represent them for example characters 0 and 1
or byte values 0 and 1?  Java has a really neat class called BitSet.
You could store one of those if you wanted.

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 27 Oct 2007 21:11 GMT
>Normally we write to files in the form of characters.
>Is there any way so that we can write data to the file in the form
>single bits like five `0's and then six `1's etc.

the smallest unit you can write to a file is a byte.  To write bits
you must compose them into bytes first.

See http://mindprod.com/applet/fileio.html
for how to write bytes.

See http://mindprod.com/jgloss/binary.html  for basic bit twiddling.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.