How to write bit in dataOutputstream in java -


i want write 2 bytes of data bit. bit value 00010000 00000000 these 2 bytes data want arrange in bit.

requirement:

1 bit - 0 1 bit - 0  1 bit - 0  1 bit - 1 1 bit - 0  1 bit - 0  1 bit - 0  1 bit - 0    4 bit - 0 1 bit - 0  1 bit - 0  2 bit - 0 

you cannot write single bit dataoutputstream. i/o granularity java classes inherit outputstream , inputstream 8 bit byte.

there few reasons this:

  • efficiency - cost of writing data 1 bit @ time prohibitive.

  • the os-level api's (syscalls) not support this; read "man 2 read" , "man 2 write" in unix / linux manual pages.

  • the places writing (files, sockets, pipes , on) modelled operating system 8 bit bytes data granularity. can't write 1 bit file without supplying 7 more.

  • 8 x n bit granularity applies down @ hardware level disk controllers, network interfaces , on. , in standards network communication ... right down iso/osi level 1.


having said that, there nothing stopping designing , implementing own java api allows write (or read) 1 bit @ time. problem @ point come interact operating system (either via java i/o classes, or in native code), api's implementation has writing (or reading) bundles of 8 x n bits.

has 1 done already? apparently, answer "yes". google "java bitstream class" or "java bitstream library". (sorry, no links because think bitstream apis nutty idea, , don't want encourage waste time them ...)


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -