Sets a specific bit of an int. : Binary Bit « Language Basics « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Language Basics » Binary Bit 




Sets a specific bit of an int.
     

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//package org.ancora.SharedLibrary;

/**
 * Methods for bit manipulation.
 *
 @author Joao Bispo
 */
public class Util{
  private static final long MASK_16_BITS = 0xFFFFL;
     private static final int MASK_BIT_1 = 0x1;
     /**
      * Sets a specific bit of an int.
      *
      @param bit the bit to set. The least significant bit is bit 0
      @param target the integer where the bit will be set
      @return the updated value of the target
      */
     public static int setBit(int bit, int target) {
        // Create mask
        int mask = << bit;
        // Set bit
        return target | mask;
     }

}

   
    
    
    
    
  














Related examples in the same category
1. Utility for byte swapping of all java data types
2.Bitwise DemoBitwise Demo
3.Binary Digits
4.Using the bitwise operatorsUsing the bitwise operators
5.Bitwise complement (~): inverts ones and zeroes in a number
6.Convert a number to negative and back
7.Bitwise AND (&)
8.Bitwise OR (|)
9.Bitwise XOR (^)
10.Left shift (<<)
11.Performing Bitwise Operations on a Bit Vector
12.Converting Between a BitSet and a Byte Array
13.Returns a byte array of at least length 1
14.Shift to the left
15.Signed shift to the right
16.Unsigned shift to the right
17.Bit-level unpacking of floating-point data
18.Gets the a single bit of the target.
19.Returns 16 bits from the long number.
20.Fuses the lower 16 bits of two ints.
21.Class to represent unsigned 32-bit numbers.
22.A list of bits.
23.Gets the specified bit (0-31) from the integer argument.
24.Sets the specified bit (0-31) in the integer argument.
25.Clears a range of bits in the specified integer.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.