|
| ||||||||||
| Tags: bit, byte, java, programming language, space allocation |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Reading file bit by bit
I am trying an program, I have one byte, in one byte each one of the 8bits means a training for an employee in my data. Code: The left most bit - orientation training The 2nd bit - management training The 3rd bit - technical training The 4th bit - operations training The 5th bit - administrative training The 6th bit - quality control training The 7th bit - sales training The 8th bit - safety training |
|
#2
| ||||
| ||||
| Re: Reading file bit by bit
Hi Code: I have one byte, in one byte each one of the 8bits means a training for an employee in my data.
__________________ Grand Theft Auto 4 PC Video Game |
|
#3
| |||
| |||
| Re: Reading file bit by bit
Hi Quote:
|
|
#4
| ||||
| ||||
| Re: Reading file bit by bit
Hi Even I am not an expert of doing this programs. But still this may help you. Code: public enum Trainingmsks {
ORI(0x80),
MAN(0x40),
TEC(0x20),
OPE(0x10),
ADMIN(0x08),
QUA(0x04),
SAL(0x02),
SAF(0x01);
private int msk;
private Trainingmsks(int msk) {
this.msk = msk;
}
public int getmsk() {
return msk;
}
public boolean istra(int test) {
return (test & msk) != 0;
}
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#5
| ||||
| ||||
| Re: Reading file bit by bit
Hi The above cod is perfect, you can also try this code. Hope this will help you Code: public class train {
public enum trainType {
ori, mana, tech, opera,
admin, qty,sal, safe
}
private EnumSet<trainType> types = EnumSet.noneOf(trainType.class);
public train(byte b) {
for(trainType t :trainType.values()) {
if((b & 1 << t.ordinal()) != 0) {
types.add(t);
}
}
}
public Set<trainType> getCanDo() {
return Collections.unmodifiableSet(types);
}
public Set<trainType> getCantDo() {
return EnumSet.complementOf(types);
}
public void add(trainType newT) {
types.add(newT);
}
public boolean istrain(trainType testT) {
return types.contains(testT);
}
public static void main(String[] args) {
train test = new train((byte)0xf2);
System.out.printf("Can do: %s%n", test.getCanDo());
System.out.printf("Can't do: %s%n%n", test.getCantDo());
test.add(trainType.tech);
for(trainType type :trainType.values()) {
System.out.printf("Can %s: %s%n", type, test.istrain(type));
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Reading file bit by bit" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading an XML file in Java | Chetna | Software Development | 7 | 13-07-2011 04:31 PM |
| Reading XML file with ASP | Dharamsi | Software Development | 4 | 10-03-2010 09:47 PM |
| Reading properties of a file | TechGate | Software Development | 5 | 14-02-2010 04:46 AM |
| Reading zip file without opening it | ISAIAH | Software Development | 5 | 22-01-2010 10:40 AM |
| Reading from INI file to several textbox in VB.NET | MABON | Software Development | 5 | 04-11-2009 08:23 PM |