Results 1 to 5 of 5

Thread: Reading file bit by bit

  1. #1
    Join Date
    Oct 2009
    Posts
    67

    Reading file bit by bit

    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.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    Oct 2009
    Posts
    67

    Re: Reading file bit by bit

    Hi
    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.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    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;
      }
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    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));
            }
        }
    }

Similar Threads

  1. Reading some file using C language
    By Vaikuntam in forum Software Development
    Replies: 9
    Last Post: 01-09-2012, 02:13 PM
  2. Pdf file reading in Micromax Q7
    By rashed823 in forum Portable Devices
    Replies: 4
    Last Post: 07-03-2011, 12:33 AM
  3. Need some help reading part of a log file...
    By agangsto in forum Operating Systems
    Replies: 2
    Last Post: 09-07-2010, 12:44 PM
  4. Reading XML file with ASP
    By Dharamsi in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:47 PM
  5. Reading a file in loop
    By Xmen in forum Software Development
    Replies: 5
    Last Post: 09-01-2010, 02:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,175,210.42014 seconds with 17 queries