Addition in Java bits, bytes and shift

Hi,
I have a byte array consisting of 8 bit values in each cell.
When I do an addition of two cells - which gives me a 16 bit result I use the following:
Integer a = (int) (arr[value] & 0xff);
a = a << 8;
Integer b = (int) (arr[secondValue] & 0xff);
Integer c = a + b;This seems to work fine. My question is how would I add 3 (24 bit result) or 4 (32 bit result) cells.
Would the following work: 24 bit result
Integer a = (int) (arr[value] & 0xff);
a = a << 16;
Integer b = (int) (arr[secondValue] & 0xff);
Integer c = (int) (arr[thirdValue] & 0xff);
Integer d = a + b + c;I am not sure if I have got the shift (<<16) usage correct or if it should be used in order to obtain the variables b or c.
All help appreciated.

khublaikhan wrote:
Just to confirm for 32 bit it would be:
// 32-bit
int a = (int)(arr[value] & 0xff);
int b = (int)(arr[secondValue] & 0xff);
int c = (int)(arr[thirdValue] & 0xff);
int d = (int)(arr[fourthValue] & 0xff);
int e = (a<<24) + (b<<16) + (c<<8) + d;
Integer eInt = new Integer(e);
Actually, the more I think about it, you may need to use longs instead of ints for 32-bit (not 16- or 24-bit though). It depends on what your data actually is. If you're expecting your 32-bit number to be an unsigned integer, then you'd better go with long. This is because in Java, ints utilize two's complement, so if the high-order byte you read in for a 32-bit value is very large, the resulting int will be interpreted by Java as a negative number instead of the large positive value you expect.
I'm probably not being very clear. Check out http://en.wikipedia.org/wiki/Two's_complement for the details.
In other words, if you wanted to get 32-bit values in this way, and the computed values are expected to be non-negative integers, use this:
// 32-bit
int a = (int)(arr[value] & 0xff);
int b = (int)(arr[secondValue] & 0xff);
int c = (int)(arr[thirdValue] & 0xff);
int d = (int)(arr[fourthValue] & 0xff);
long e = (a<<24) + (b<<16) + (c<<8) + d;
Long l = new Long(e);If you're actually reading in a 32-bit, two's complement value, then keep using int like you originally posted.

Similar Messages

  • Bits, bytes, and all the rest

    I need clarification on what some stuff really represents.
    My project is to build a Huffman tree (no problem). However, all tutorials and examples that I can find on the net take from a text file with the format <letter> <frequency>, such as:
    a 12
    b 3
    c 4
    d 8
    Mine has to read any kind of file, such as a text file.
    For example, if myDoc.txt contains:
    This is my document.
    I have to have my program read the bytes from the infile, count the frequency of each byte from 0 through 255. Then the frequencies must be placed on a list of single node Huffman trees, and build the tree from this list.
    I think I am having trouble because I just cannot get straight what a byte "looks like". My project says ensure you are not counting the "letters" of the infile, but the "bytes".
    So what does a byte look like? When I read in the file as above, what is a "byte" representation of the letter T, i,h, etc?
    Any ideas?

    Ok, Roshelle....here is a little history lesson that you should have learned or should have been explained to you by your instructor before he/she gave you the assignment to construct a Huffman tree.
    A bit is a binary digit which is either 0 or 1 -- it is the only thing that a computer truly understands. Think about it this way, when you turn on the light switch, the light comes on (the computer sees it as a 1), when you turned the switch off, the light goes out (the computer sees it as a 0).
    There are 8 bits to a byte -- you can think of it as a mouthful. In a binary number system, 2 to the power of 8 gives you 256. So, computer scientists decided to use this as a basis for assigning a numerical value to each letter of the English alphabets, the digits 0 to 9, some special symbols as well as invisible characters. For example, 0 is equivalent to what is known as null, 1 is CTRL A, 2 is CTRL B, etc...... (this may vary depending on the computer manufacturers).
    Now, what was your question again (make sure that you count the byte and not the letters)?
    As you can see, when you read data from a file, there may be characters that you don't see such as a carriage return, line feed, tab, etc.....
    And like they said, the rest is up to the students!
    V.V.

  • Bits, bytes and megabits

    In telecommunications (data rates) 1,000,000 bits in a megabit, apparently.
    In computing (file size)  1,048,576 bytes in a megabyte, apparently (1,048,576 bits in a megabit)
    There are different names available to distinguish them (e.g. kibibit/kilobit) but apparently, these and similar are often not used. Result? Confusion. http://en.wikipedia.org/wiki/Megabyte
    I suspect that quite a few people don't realise this - I didn't. Makes a difference when you are trying to check your upload and download speeds and verify BT's claims about their speeds. 

    The way I do it is X the results on speedtesters that give results in kbps [something like 74500/15500] by 1024.
    The fake results above would be 74500x1024 = 76288000Kbps which = 76.28Mbps [approx 76.3Mbps] which is very near the line max after overheads.cool.
    74954kbps = 76752896Kbps = 76.7Mbps
    15207 = 15571968Kbps = 15.6Mbps
    these are my actual readings.

  • Byte addition in java....problem!

    Hello:
    I am trying to calculate the 16bit checksum for an array of bytes that I have.....for some reason it doesnt work, the same code works just fine in C and C++......i am sure this has to do with the representation of data in java......any comments would be great.
    Note: pucInBuffer <======== byte[]
    the code is .................
    int iExpectedChecksum = 1500;
    int iCalculatedCheckSum = 0;
    int iStart = 1;
    for(i = iStart; i <= iEnd; i++)
    iCalculatedCheckSum = iCalculatedCheckSum + arg_pucInBuffer;
    end of code .......................
    this never seems to work, what I am doing wrong? the number I get out always wrong, it never matches the 16bit number that suppose to come out. I even did a mask on the upper two bytes of the iCalculatedCheckSum , still didnt work.......
    any ideas?
    thanx

    Hardware doesn't support adding an 8 bit value and a 32 bit value. When Java does a binary operation like addition, both operands must be of the same type. The rules for this are in section 5.6.2 of the JLS at http://java.sun.com/docs/books/jls/second_edition/html/jTOC.doc.html
    C and C++ do the same thing. The difference is that you were probably using unsigned char for your byte values. Those always get converted to positive ints before the addition.

  • Fresh Bits! Oracle Java ME Embedded and ME SDK updates

    Oracle has just refreshed the Java ME Embedded 3.3 EA and ME SDK 3.3 EA binaries.
    For more information, please see my blog: https://terrencebarr.wordpress.com/2013/06/13/fresh-bits-oracle-java-me-embedded-and-me-sdk-updates/
    Best regards,
    Terrence Barr
    Principal Product Manager, Oracle

    Hello,
    I am just viewing this course now and am stuck on finding the raspberry pi 8.1 EA binary:
    oracle-jmee-8-1-ea-raspberrypi-linux-bin-b01-20_may_2014.zip
    The only thing I can find on this page (which is what the document your link brings up has)
    http://www.oracle.com/technetwork/java/embedded/javame/embed-me/downloads/index.html
    is 8.0:
    oracle-jmee-8-0-rr-raspberrypi-linux-bin.zip
    Please help...
    Thanks

  • Rotate and Shift 16-bit Image

    I would like to rotate and shift a 16-bit RGB image (U64 in LabVIEW).  The IMAQ rotate and shift functions don't accept this image type, but they do accept a 16-bit grayscale image (I16 in LabVIEW).  Unfortunately, this clips all values in my original image since it runs from -32,767 to + 32,767.  The ExtractColorPlanes function requires a 16-bit image to be wired as the desination image but the IMAQ create VI does not allow U16 image to be created.
    Any ideas?
    Solved!
    Go to Solution.

    SJT a écrit:
    I would like to rotate and shift a 16-bit RGB image (U64 in LabVIEW).  The IMAQ rotate and shift functions don't accept this image type, but they do accept a 16-bit grayscale image (I16 in LabVIEW).  Unfortunately, this clips all values in my original image since it runs from -32,767 to + 32,767.  The ExtractColorPlanes function requires a 16-bit image to be wired as the desination image but the IMAQ create VI does not allow U16 image to be created.
    IMAQ Create can create U16 images, but the standard Image Type input lack the appropriate value. This is bug n°1 . As workaround, you can either wire directly a con,stant with value 7 or dig into the Vision palettes and get a better typed constant from the IMAQ Cast Image VI.
    However, this is not the solution to your problem, since there is the n°2 bug in the IMAQ ExtractSingleColorPlane VI : it doesn't accept U16 or U64 as destination images, and coerce the output to a I16 default image type.
    A workaround is to create your own color plane extraction function. First convert the U64 image into an array, then extract the desired plane, as shown on the diagram below.
    Message Edité par chilly charly le 12-30-2008 08:31 AM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Extract Color Plane U64.vi.zip ‏15 KB
    U16 ExtractSingleColorPlane.vi.zip ‏13 KB
    U16 ExtractSingleColorPlane_BD.png ‏10 KB

  • Trying to understand the details of converting an int to a byte[] and back

    I found the following code to convert ints into bytes and wanted to understand it better:
    public static final byte[] intToByteArray(int value) {
    return new byte[]{
    (byte)(value >>> 24), (byte)(value >> 16 & 0xff), (byte)(value >> 8 & 0xff), (byte)(value & 0xff) };
    }I understand that an int requires 4 bytes and that each byte allows for a power of 8. But, sadly, I can't figure out how to directly translate the code above? Can someone recommend a site that explains the following:
    1. >>> and >>
    2. Oxff.
    3. Masks vs. casts.
    thanks so much.

    By the way, people often introduce this redundancy (as in your example above):
    (byte)(i >> 8 & 0xFF)When this suffices:
    (byte)(i >> 8)Since by [JLS 5.1.3|http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363] :
    A narrowing conversion of a signed integer to an integral type T simply discards all but the n lowest order bits, where n is the number of bits used to represent type T.Casting to a byte is merely keeping only the lower order 8 bits, and (anything & 0xFF) is simply clearing all but the lower order 8 bits. So it's redundant. Or I could just show you the more simple proof: try absolutely every value of int as an input and see if they ever differ:
       public static void main(String[] args) {
          for ( int i = Integer.MIN_VALUE;; i++ ) {
             if ( i % 100000000 == 0 ) {
                //report progress
                System.out.println("i=" + i);
             if ( (byte)(i >> 8 & 0xff) != (byte)(i >> 8) ) {
                System.out.println("ANOMOLY: " + i);
             if ( i == Integer.MAX_VALUE ) {
                break;
       }Needless to say, they don't ever differ. Where masking does matter is when you're widening (say from a byte to an int):
       public static void main(String[] args) {
          byte b = -1;
          int i = b;
          int j = b & 0xFF;
          System.out.println("i: " + i + " j: " + j);
       }That's because bytes are signed, and when you widen a signed negative integer to a wider integer, you get 1s in the higher bits, not 0s due to sign-extension. See [http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.2]
    Edited by: endasil on 3-Dec-2009 4:53 PM

  • Concat 4 8-bit bytes into 1 32-bit word

    I am just getting started up with LabView. I have an FPGA that is sending a signed (2's Comp) 32 bit vector to the PC serial port in four 8-bit chunks. I am having trouble figuring out how to recombine the four bytes into the original 32-bit word. It is a simple task in any programming language using concatenation but I am really having problems with this.
    Thanks
    Jeremy

    Two ways come to mind immediately.
    1) Go from a string (VISA returns a string from a read) to a byte array then loop and shift each byte the correct amount while OR'ing the result with that from each loop iteration.
    2) Use the join numbers vi to combine multiple bytes into a single 32-bit word.
    I've attached a vi that demonstrates these two solutions.
    Attachments:
    MergeBytesExample.vi ‏28 KB

  • Bits & Bytes

    Hi,
    I'm trying to reach a binary switch file. The file consists of bytes. Each byte consists of 4 bits, e.g., in my first byte position I have 02. I'm trying to read this binary file and write to another file in decoded ASCII/Hex format. I'm facing following problems :
    1. If the value is less than 0xF, I'm not able to process the byte.
    1.1) The byte is always being read in reverse order, i.e., 20 instead of 02. This problem is also when I read any byte..whether greater than or less than 0xF. But for values greater than 0xF, I'm taking them in a String array and writing it in reverse order.
    So, when I read the first bit, the control comes out of the function where I'm doing the processing, into main, and when the control goes back into the funtcion, it again reads the byte read earlier. If I try to take the values in a 2D array, the value is over written.
    2. How do I check for EOF in a binary file?
    So, how should I handle this. Any answers??? My code is shown below :
    Thanks & regards,
    Faisal
    import java.io.*;
    public class fileinputstream1_3
    static FileInputStream inFile;
    static FileOutputStream outFile;
    static FileWriter fileWriter;
    static DataInputStream inData;
    static PrintWriter outData;
    public static void toHex(byte v) throws IOException
    double tempVal1 = 0;
    double tempVal2 = 0;
    double tempVal3 = 0;
    double tempVal4 = 0;
    int tempVal5 = 0;
    int tempVal8 = 0;
    int testVal1 = 0;
    int j = 0;
    String testVal;
    String tempVal6 = "";
    String tempVal7[] = new String[2];     
    tempVal7[1] = "";                
    File f = new File( System.getProperty( "Programs" ), "cdr6.txt" ); // find path to o/p file
    fileWriter = new FileWriter( f, true );
    outData = new PrintWriter(fileWriter);
    // Convert a 4-bit value into a hex digit char
    if (v >= 0x0 && v <= 0xF)
         fileWriter.write(((char)(v < 0xA ? v+'0' : v-0xA+'A')));
         else      
         if ( v > 0xF )
         tempVal1 = (double) v;
         while ( tempVal1 > 1.0 )
         tempVal1 = tempVal1 / 16.0;
         tempVal2 = (int) tempVal1;
         tempVal3 = tempVal1 - tempVal2;
         tempVal4 = tempVal3 * 16;
         if ( tempVal4 >= 10.0 )
         tempVal5 = (int)tempVal4;
         tempVal6 = Integer.toHexString( 0x10000 | tempVal5).substring(4).toUpperCase();
         else
         tempVal5 = (int)tempVal4;
         if ( tempVal6 == "" )
              tempVal6 = Integer.toString(tempVal5);
              testVal = Double.toString(tempVal4);
              testVal1 = (int)tempVal4;
              tempVal1 = tempVal2;
              tempVal7[0] = Integer.toString(testVal1);
              tempVal7[1] = tempVal6;
         try
         for ( int i = 0; i <= 1; i++ )
         fileWriter.write(tempVal7);
         catch ( IOException ioe )
         System.out.println( "Could not open the files. " +ioe );
         fileWriter.flush();
         fileWriter.close();
         System.out.println("Exiting toHex.");
    public static void main(String[] args) throws Exception, IOException
    int x;
    int size;
    File f = new File( System.getProperty( "Programs" ), "cdr1");
    try
    inFile = new FileInputStream( f );     // open the input binary file
    inData = new DataInputStream( inFile ); // associate an input stream to the file
    f = new File( System.getProperty( "Programs" ), "cdr3.txt" ); // find path to o/p file
    // this is just to reproduce the input file - not much practical use
    outFile = new FileOutputStream( f );
    outData = new PrintWriter( outFile,true );               
    catch ( IOException ioe )
    System.out.println( "Could not open the files. " +ioe );
    try
    byte bytearray[] = new byte[size+1];
    for (int loop_index = 0; loop_index < bytearray.length ; loop_index++ )
    outFile.write(bytearray[loop_index]);
    toHex(bytearray[loop_index]);
    outFile.write(1);
    catch ( IOException ioe)
    System.out.println( " IO error " + ioe + " occured.");
         System.out.println("Exiting main...");
         System.in.read();

    Hi,
    I don't understand the question. A byte is alwaysa
    byte, and a byte is always 8 bits, and there's no
    /KajNot necessarilly. While currently more or less
    standardised there is hardware that has wider or
    narrower bytes.
    Whether Java is supported on those platforms and how
    it would handle such situations if it were I don't
    know.But a byte is still 8 bits, even if the hardware uses 9 bits internally (let's say that the hardware uses one bit for crc)??
    I might make a slight change to; In java a byte is always 8 bits :)

  • Bytes and hex woes

    I am sending data to the serial port and it must be in hexadecimal format. I'm using a method that sends a byte array to the serial port.
    putData(byte[] barray);I've created a byte[] array and initialized it to the following values.
    byte byteBuf[] = {  0x10, 0x40, 0x80 };
    How can I be sure that the 0x prefix is being sent. Namely, how can I send the hex value in the byte array. Also, I get a
    possible loss of precision error
    found : int
    required: byte
    byte byteBuf[] = {  0x10, 0x40, 0x80 };
                                ^     ^
    Any ideas would be greatly appreciated, Cheers.

    Because of the way two's complement binary and signed bytes work. Your 0x80 byte is expressed in binary as 10000000. This is the equivalent of -128 in decimal by virtue of Java's bytes always being signed (the leftmost bit indicates whether the byte is positive or negative). When you run the conversion to an integer, it has the binary look of:
    11111111 11111111 11111111 10000000
    This is still -128 in decimal. When you then convert this to a hex String, it looks at each "octet", so the integer then becomes:
    11111111 = FF
    11111111 = FF
    11111111 = FF
    10000000 = 80
    Or, FFFFFF80.
    Make sense?

  • Java Bit arithmatic support?

    Does java provide support for bitwise operation as does C++ and many other languages?
    It seems tht as a fully OO language, it should implement some very powerfull classes for bit manipulation and such. If you could point me in the right direction for learning the support, it would be great.
    ~Andy

    Besides the BitSet class that was already provided in another answer, java also has the bitwise operators:
    Bitwise and: &
    Bitwise or: |
    Bitwise complement: ~
    Bitwise xor: ^
    Bitwise left shift: <<
    Bitwise signed right shift: >>
    Bitwise unsigned right shift: >>>
    tajenkins

  • Byte and char !!!

    Hi!
    What is the diference between an byte and char in Java! Could I use char instead of byte and reverse?
    Thanks.

    TYPE BYTE BITS SIGN RANGE
    byte 1 8 SIGNED -128 to 127
    char 2 16 UNSIGNED \u0000 to \uFFFF
    Both the date types can be interchanged
    Have a look at this
    class UText
         public static void main(String[] args)
              byte c1;          
              char c2= 'a';
              c1 = (byte) c2;
              c2 = (char) c1;          
              System.out.println(c1 +" "+c2);
    But It Leads to confusion while interchanging because of its SIGN. And the range of byte is very less.So its better to prefer char.

  • VPN Client on Windows 7 64 Bit Enterprise and T410 Very Slow to Load

    Hello,
    I have the 64 bit Client 5.0.0.7.0290 loaded on Thinkpad T410s running Windows 7 64 Bit Enterprise and it takes over an hour for the client to execute.  Each step of the client load takes 10-15 minutes to load and although the interface eventually loads; it does not allow me to connect.
    It happens on all the T410s which are all running Windows 7 64 Bit. Our other Windows 7 64-Bit  Laptops and Desktops run this client just fine.  I have tried to load the client as the first app after the Windows 7 has completed its install from the Microsoft DVD and I get the same response.
    Any suggestions on how I can debug this issue?  I have tried process explorer and it does not show any hung processes.
    Many thanks,
    Kevin

    Hi all,
    thanks for your suggestions.
    Unfortunately both errors still remain.
    1)  Web Intelligence Rich Client
    I  have  installed BOE client tools using XI3.1 SP3 Client tools package in C:\Business Objects. The report's import runs well, but when i try to open one of the imported reports, i receive the error: WIJ 2002.
    The details are:
    Version:null Analisi dello stack: java.lang.RuntimeException: java.lang.RuntimeException: XML parser problem: XMLJaxpParser.parse(): Element type "ABOUT_Patentnumbers" must be followed by either attribute specifications, ">" or "/>". at com.businessobjects.wp.xml.jaxp.XMLJaxpParser.parse(Unknown Source) at com.businessobjects.webi.richclient.XMLviaOccaRC.getServerConfiguration(Unknown Source) at com.businessobjects.wp.xml.XMLServerConfiguration.load(Unknown Source) at com.businessobjects.wp.xml.XMLServerConfiguration.load(Unknown Source) at com.businessobjects.wp.tc.TCMain.initClient(Unknown Source) at com.businessobjects.wp.tc.thread.InitAppletRunner.run(Unknown Source) at java.lang.Thread.run(Unknown Source)  at com.businessobjects.webi.richclient.XMLviaOccaRC.getServerConfiguration(Unknown Source) at com.businessobjects.wp.xml.XMLServerConfiguration.load(Unknown Source) at com.businessobjects.wp.xml.XMLServerConfiguration.load(Unknown Source) at com.businessobjects.wp.tc.TCMain.initClient(Unknown Source) at com.businessobjects.wp.tc.thread.InitAppletRunner.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
    2) Infoview
    We have installed java 1.6.0_02 (we previously have Update 29).
    We try to use Explorer 9.0.3 or Firefox 8.0
    Any other suggestion???
    Thanks

  • I'm a long time PC user and just bought a 64 bit iMac and want to use BootCamp to play old PC games.  Can I install Win XP or if it needs Win 7 can it be a 32 bit version, and how do I do it?

    I'm a long time PC user and just bought a 64 bit iMac and want to use BootCamp to play old PC games.  Can I install Win XP or if it needs Win 7 can it be a 32 bit version, and how do I do it?

    Once you get windoze up an running on your new iMac, see these:
    Switching from Windows to Mac OS X,
    Basic Tutorials on using a Mac,
    Mac OS X keyboard shortcuts,
    Anatomy of a Mac,
    MacTips,
    Switching to Mac Superguide, and
    Switching to the Mac: The Missing Manual, Mountain Lion Edition.
    Additionally, *Texas Mac Man* recommends:
    Quick Assist,
    Welcome to the Switch To A Mac Guides,
    Take Control E-books, and
    A guide for switching to a Mac.

  • I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    Hello,
    You mention that you send a string to the microprocessor that tells it how many bytes to send. Instead of requesting 512 bytes, try reading 10 times and only requesting about 50 bytes at a time.
    If that doesn�t help, try directly communicating with your microprocessor through HyperTerminal. If you are not on a Windows system, please let me know. Also, if you are using an NI serial board instead of your computer�s serial port, let me know.
    In Windows XP, go to Start, Programs, Accessories, Communications, and select HyperTerminal.
    Enter a name for the connection and click OK.
    In the next pop-up dialog, choose the COM port you are using to communicate with your device and click OK.
    In the final pop
    -up dialog, set the communication settings for communicating with your device.
    Type the same commands you sent through LabVIEW and observe if you can receive the first 54 bytes you mention. Also observe if data is returned from your 512 byte request or if HyperTerminal just waits.
    If you do not receive the 512 byte request through HyperTerminal, your microprocessor is unable to communicate with your computer at a low level. LabVIEW uses the same Windows DLLs as HyperTerminal for serial communication. Double check the instrument user manual for any additional information that may be necessary to communicate.
    Please let me know the results from the above test in HyperTerminal. We can then proceed from there.
    Grant M.
    National Instruments

Maybe you are looking for

  • Portal Activity Reports Combinations

    Dear Portalites, I am confiuring a Portal Activity Reporting iView.  And I have some fundamental issues The Environment A. Webdynpro Java Applications running on normal Enterprise Portal Environment B. Custom Built JAVA applications runing on URL iVi

  • Looking for a 'Camera Viewfinder' simulator plugin

    I remember an old plugin for iMovie that made the image look as if it was from a camcorder's viewfinder - with a red light, "REC" and everything framed in a box. I can't find that in the new iMovie 6 effects. Might anyone know if/where such a thing e

  • Challenging Personal Guaranty with Capital One

    Hi,  new member here, although I've been reading on this board for over a year. I own a small C Corporation and have been settling my debt with numerous Credit Card companies.  I've actually settled 7 out of 8 in the last 1 1/2 years leaving only a C

  • Starting out with Guitar Recording in Garageband

    I started playing guitar about 2 years ago, and I'm just now starting to get interested in composing my own material. Im on an extremely tight budget (I'm broke after buying my first Mac Though I'm very happy with it.) I earlier tried plugging the gu

  • DV6 Power supply

    The power supply for my DV6 makes this quiet, yet noticeable crackling noise. I bought the laptop a month ago, and I started to notice this noise about 2 weeks ago, it happens all the time when the laptop is plugged in. I'd imagine this isn't suppose