Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


Reading file bit by bit

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 14-12-2009
Member
 
Join Date: Oct 2009
Posts: 67
Reading file bit by bit

Sponsored Links
Hi
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
The main problem is I can not read what training an employee has.

Reply With Quote
  #2  
Old 14-12-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,382
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.
I think it is better if you read the data in bytes and then operate on the bytes to get the information.
Reply With Quote
  #3  
Old 14-12-2009
Member
 
Join Date: Oct 2009
Posts: 67
Re: Reading file bit by bit

Hi
Quote:
I think it is better if you read the data in bytes and then operate on the bytes to get the information.
I am not used to operating with bytes and so I do not try that. The byte I have is a certain value. I think I would not be able to do it. Since the dat allows a employee to have more than one type of training. So, I have to state all types of possibility.
Reply With Quote
  #4  
Old 14-12-2009
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,382
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;
  }
}
Reply With Quote
  #5  
Old 14-12-2009
MindSpace's Avatar
Member
 
Join Date: Feb 2008
Posts: 1,839
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));
        }
    }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 11:49 AM.