Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Writing single bits to a file

Reply
Thread Tools

Writing single bits to a file

 
 
riva
Guest
Posts: n/a
 
      10-27-2007
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.

 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      10-27-2007
riva wrote:
> 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.

--

Knute Johnson
email s/nospam/knute/
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-27-2007
On Sat, 27 Oct 2007 17:31:56 -0000, riva <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>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.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing single bits to a file riva C Programming 64 11-12-2007 12:11 PM
shifting bits, shift 32 bits on 32 bit int GGG C++ 10 07-06-2006 06:09 AM
8 bits/ch vs 16 bits/ch in PS Terry Digital Photography 5 01-21-2004 06:59 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM
win XP 32 bits on a 64 bits processor.. Abbyss Computer Support 3 11-13-2003 12:39 AM



Advertisments