Writing single bits to a file

Discussion in 'Java' started by riva, Oct 27, 2007.

  1. riva

    riva Guest

    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.
     
    riva, Oct 27, 2007
    #1
    1. Advertising

  2. 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/
     
    Knute Johnson, Oct 27, 2007
    #2
    1. Advertising

  3. riva

    Roedy Green Guest

    On Sat, 27 Oct 2007 17:31:56 -0000, riva <>
    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
     
    Roedy Green, Oct 27, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GGG
    Replies:
    10
    Views:
    12,635
    Donar
    Jul 6, 2006
  2. sarmin kho
    Replies:
    2
    Views:
    840
    A. Lloyd Flanagan
    Jun 15, 2004
  3. Miki Tebeka
    Replies:
    1
    Views:
    452
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  4. sergey

    "casting" bits to bits?

    sergey, Nov 8, 2006, in forum: VHDL
    Replies:
    1
    Views:
    720
    sergey
    Nov 8, 2006
  5. riva

    Writing single bits to a file

    riva, Oct 26, 2007, in forum: C Programming
    Replies:
    64
    Views:
    1,384
    James Kuyper
    Nov 12, 2007
Loading...

Share This Page