Byte - Integer Conversion

I have four bytes that I want to store directly into an integer and then read back out again. I've spent forever trying bitshifts and division/modulo, but to no avail...with Java not supporting unsigned values, I can't figure it out...what I want is this:
[00000000][00000000][00000000][00001111] (four individual bytes)
STEP ONE: is converted to
[00000000000000000000000000001111] (same sequence of bits in an int)
and then some operation is performed (let's say adding one)
[00000000000000000000000000010000] (addition on the integer)
STEP TWO: and afterwards the integer is converted back
[00000000][00000000][00000000][00010000] (four individual bytes)

use parenthesis a lot until you know operator precedence
and use 0xff & byte to get rid of sign extension
public class ByteInt {
public static void main(String[] args) {
  int i;
  byte b3, b2, b1, b0;  // b3 is highest order byte
  b3 = 0x12;
  b2 = 0x34;
  b1 = 0x56;
  b0 = 0x78;
  i = (0xff & b0) | ( (0xff & b1) << 8  )
                  | ( (0xff & b2) << 16 )
                  | ( (0xff & b3) << 24 );
  System.out.println(Integer.toHexString(i));
  System.out.println("");
  i = 0xf1827456;  // f1 82 74 56
  System.out.println(Integer.toHexString(i));
  System.out.println("");
  b0 = (byte)   (i & 0xff);
  b1 = (byte) ( (i & 0xff00)     >> 8  );
  b2 = (byte) ( (i & 0xff0000)   >> 16 );
  b3 = (byte) ( (i & 0xff000000) >> 24 );
  System.out.println(Integer.toHexString(b3));
  System.out.println(Integer.toHexString(b2));
  System.out.println(Integer.toHexString(b1));
  System.out.println(Integer.toHexString(b0));
  System.out.println("");
  System.out.println(Integer.toHexString(0xff & b3));
  System.out.println(Integer.toHexString(0xff & b2));
  System.out.println(Integer.toHexString(0xff & b1));
  System.out.println(Integer.toHexString(0xff & b0));
  System.out.println("");
} // method
} // class

Similar Messages

  • OutOfMemoryError on new byte[Integer.MAX_VALUE]. Why, how to fix?

    Hello,
    I am getting an OutOfMemoryException when I am initializing a new array of bytes:
    byte[] barr = new byte[Integer.MAX_VALUE];
    Why?
    Thanks,
    Corrine

    Well, I am dealing with 32-bit values, and eachelement of the array corresponds to one of twooptions
    for each bit.
    Why are you choosing to do this?Because the array is supposed to be a grayscale map
    for a 32-bit image.Okay, maybe my question wasn't clear enough. Why have
    you set your requirements to use a byte array in which
    each byte serves to represent a single bit as a
    representation of a grayscale map of a 32-bit image?
    Can you post some code? Why have you chosen to
    allocate ~2GB of RAM to work with a single image?
    There has got to be a better way to accomplish what
    you're trying to do.
    The answer to your question is because as I understand it, the structure of the grayscale map that I'm using corresponds to the required specification in defining an associated IndexColorModel.

  • I have doubt regarding the byte to integer conversion.

    In java card epurse application the output we see is in bytes.to convert this byte to integer which is understandable by the end-user what should be done?

    809295 wrote:
    In java card epurse application the output we see is in bytes .
    to convert this byte to integer which is understandable by the end-user what should be done?What do you mean by we ?
    How many bytes ?
    On a java card platform support for integer is optional, you may only have short.
    I assume by understandable by the end-user you mean display as a sequence of decimal digits ?
    So two bytes 0x04 0xd2 (combined to a short 0x04d2 which is 1234 decimal)
    should be presented to the user as 0x31 0x32 0x33 0x34 (ascii values for '1' '2' '3' '4').

  • Hex decimal n.o to integer conversion?

    how to convert 1 byte hex n.o in decimal form to the decimal integer of of 8 bit data .
    Solved!
    Go to Solution.

    Hi,
    You can use the Hexadecimal to Number fucntion. This is available in - Programming>String>String/Number Conversion.
    Alternatively you can search for hexadecimal to number conversion.
    Regards,
    Kanchan Bhakoo
    Applications Engineer | National Instruments

  • Byte String conversion

    Problems reading a byte string. Has been a 16 bit number chopped into 2 bytes. Within Java we read the 2 bytes as below at the moment using an int []
    We sandwich it back together again but now and again the values seem to get muddled up. Example I can see the raw data sitting at 148 yet when the code is executed it says it is 28. Any ideas????
    String file = "HISTORY_data.out";
              m_historyInputStream=new FileInputStream( file );
              m_bufferedReader=new BufferedReader(new InputStreamReader( m_historyInputStream )) ;
              for (int i = 0; i <512; i++)
                   m_historyBuffer[i] = (byte)m_bufferedReader.read();
              // Read last startup ECG sector counter
              UpperByte = m_historyBuffer[72];
              LowerByte = m_historyBuffer[73];
              m_iECGSecStart = (UpperByte << 8) | (LowerByte & 0x00FF);

    When you use a Reader, the bytes are converted to characters, and in this process sometimes 2 or 3 bytes can be used to make up a character depending on the character encoding that is used with the Reader. This is usually some default character encoding, unless you provide your own. If you insist to use a Reader, and you want a 1 to 1 mapping between a byte and char, then use the ISO 8859-1 character encoding:
    m_bufferedReader = new BufferedReader(new InputStreamReader(m_historyInputStream, "8859_1"));But there is no need to do so. You would be better of using the BufferedOutputStream, and everything would have worked.
    And as mentioned before, there are other input/outputstreams that can convert 16-bit numbers to bytes and viceversa. Ints are 32-bit long, so when you read/write an int, it takes up 4 bytes, unless you convert it to a short. The primitives in java are signed, so you have to be careful with converting an int to a short and back to an int (you have to & with 0xFFFF if the short to int conversion should always be positive).

  • Send and recieve 2 byte integer values.

    hi,
    basically i'm trying to allow my applet and servlet communicate using 2 byte signed integer values. but i haven't figured out how to store an integer value into a byte array of size 2, or unpack it once it gets there.
    here's some code/psuedocode that i've done so far.
    SERVLET:
    ByteArrayOutputStream bst = new ByteArrayOutputStream(streamsize);
    ServletOutputStream bout;
    byte[] strm = new byte[streamsize];
    byte[] dbyte = new byte[2];
    int[] testarr = new int[10];
    /* fill my testarr with values... */
    bout = response.getOutputStream();
    int l = 0;
    for (int i = 0;i<arraysize;i++){
    getDoubleByteFromInteger(dbyte,testarr)
    strm[l++] = dbyte[0];
    strm[l++] = dbyte[1];
    bst.write(strm,0,streamsize);
    bst.writeTo(bout);
    APPLET:
    /* connect to servlet and get binary stream */
    bytecount = in.read(streamb);
    byte[] db = new byte[2];
    counter = 0;
    while (cursor < bytecount){
    db[0] = streamb[cursor++];
    db[1] = streamb[cursor++];
    array[counter++] = getIntFromByte(db);
    the functions getIntFromByte and getDoubleByteFromInteger haven't been written, can anyone give me a little push? or tell me if this is something possible? thanks for any help
    Matt

    The primitive type short is a two-byte signed integer, so you really don't need to bother with byte arrays - just use DataOutputStream to write it (it has a method called writeShort) and DataInputStream to read it (with readShort()).
    But anyway, getting an int from two bytes and getting two bytes from an int is easy with the bitwise operators:
    int -> byte array
    int i = yourInt;
    byte[] b = new byte[2];
    b[1] = (byte) (i >> 8);
    b[0] = (byte) (i);
    byte array -> int (unsigned)
    int i = ((b[1] & 0xFF) <<8) + (b[0] & 0xFF);
    byte array -> short -> int (signed)
    short s = (short) ((b[1] & 0xFF) <<8) + (b[0] & 0xFF);
    int i = s;

  • Character to Integer Conversion

    hi all,
    can anyone please tell me that how to convert Charecter to Integer? i have a value in
    itab-kunnr = '0000023004'. i have to remove 0 in left side and need value only '23004'.
    KUNNR is a Charecter.
    regards saurabh.

    hi
    you can use MOVE, write or just assign it to the
    required variables.
    just have a look at the documentation for the MOVE
    hope this helps
    regards
    Aakash Banga

  • Represent an 4-byte integer as a hex number???

    Hi everyone,
    I still have problem with converting an IP address to an POSITIVE number. One of the native method expects unsigned integer pass in to set IP address for a device. But, in java, when I convert a big IP such as 192.0.0.0, it will return a negative integer. Many of people helped me out but I still got the problem since my co-worker did not want to change his code. He wanted me to find an alternative way to do. He suggested me to represent the address in hex format will work ok.
    e.g int ipAddr = 0x6C01A7C0; // 192.167.1.108
    Then CallCOMObject(ipAddr);
    So, my question is do we have a way to convert 192.167.1.108 into 0x6C01A7C0?
    Thanks in advance
    Hung.

    Hi Armalcolm,
    Yes, I tried that but the native function throwed exception since the integer I pass in was negative. In the native function, there was an IF statement which would reject all negative integer.
    Here is my example
    After user enter IP as: 192.167.1.108, I convert (by shifting and adding) to an integer and I got an negative integer (-1062796948). Then I passed it in the native function as:
    CallCOMObject(-1062796948);
    The native function throwed exception.
    Is that what you mean, Armalcolm?
    Alternatively, you could do your shifting and adding into a long, and then and the result with >0xffffffff, passing the result. But there should not be any difference. I could shifting and adding into a long, but I don't know how to represent that long number in hex. Can you help me out with that.
    I appreciate for your reply.
    Hung.

  • Error in Integer conversion method  equals(...)???

    Example:
    Integer I = new Integer(0);
    If (i.equals(0))
    �.
    As far as I know, equals(Object obj)�. Therefore, i.equals(0) should generate a compilation error. However, I teststed this with JCreator with the latest 1.6.0_03 jdk. It accepts it and treat the �0� as the actual value.
    Therefore, if I do:
    Integer I = new Integer(0);
    If (i.equals(0))
    �.
    i.equals(0) return true. Shouldn't it be invalid instead? If returning true is correct, your documentation should reflect so. http://java.sun.com/docs/books/tutorial/java/data/numberclasses.html.
    Input is greatly appreciated.

    That's due to autoboxing. See http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
    If you want to see something really screwy, what do you think this returns?
    Object o = true ? new Integer(1) : new Double(2.0);

  • Modbus real to unsigned integer conversion

    Is there any alternative way of decoding the two unsigned integer 16 bit words received through Modbus when using reals? I am using the join numbers and type cast functions; however I am not able to download the complete Modbus list to a compact RIO with 32 MB RAM as it runs out of memory.

    Khalid,
    Thanks for your response. However, let me tell you more about my problem:
    Basically my project consists of:
    1. A list of shared variables within a library that also contains modbus slave with the communication settings.
    2. (5) VIs that used to convert UInt16 to Single (for inputs) and Single to UInt16 (for otputs)
    3. (1) VI to display information
    As I try to download into a cRIO-9002 with 32MB of RAM, the device drops the communication and goes into safe mode, blinking the STATUS light 4 times, this means "run out of memory" .
    I would like to know if there is any other alternative way to overcome this problem. Join and cast is functionally correct but it uses too much RAM

  • Integer conversion

    hi can any one tell me about any APIs for converting from hexadecimal value to a decimal value ie
    int a =0x23;
    now i want int b = decimal value of a
    is ther aby built in support to do this in java???

    hey guys
    i am getting it as a String like
    String s = "0x34";
    now i want the decimal value of 34Eh?
    Typically "0x34" would mean it's a base-16 number, so the decimal value would be 52, not 34. Was that what you meant?
    If so, then strip off the leading "0x" as you're doing and call parseInt, as Dick_Adams suggests. That is, if you want an int. If you want an Integer, then use valueOf. Although I suppose autoboxing/unboxing will render the two equivalent here. I'd still use the one whose return type matches what you want to end up with though.

  • Object stream and byte array conversion

    Hello everyone,
    I am wondeirng how to convert an ObjectInputStream to a byte array, then convert the array back to ObjectInputStream -- should I convert the array back to ObjectOutputStream other than ObjectInputStream?
    Any sample codes?
    thanks in advance,
    George

    Isn't it the other way around? You can't do this directly:
    ObjectInputStream ois = ...;
    ByteArrayInputStream bais = new ByteArrayInputStream(ois);(but you can do it indirectly), but you can do this:
    ByteArrayInputStream bais = ...;
    ObjectInputStream ois = new ObjectInputStream(bais);

  • Unsigned int to integer conversion

    Hi,
    I have an unsigned integer column in my database table. If I try to retreive the value of the column using resultset.getInt() I'm getting "Numeric value overflow" error as it exceeds the INT_MAX value.
    For eg., if the column value : 4294967295, the expected value from resultset.getInt() is -1 or Numeric Value Overflow error ?
    Is it valid to retrieve the value using getInt() or should I use getLong()?.
    Kindly Clarify.
    Thanks,
    Radhika.

    use getLong

  • Conversion of String to byte[ ]

    Hi everybody
    I have a Byte[] value in one of our client database it seems like this -- 00033DB7FB87EC4EB371BCC9D3BF13EC
    when they import into CSV it became String
    I need to Dump into my database what ever you see in that Byte[].the value is already a conversion only so i need to dump as it is.
    now the real problem is how to convert the same String as Bytes
    if i use String.getBytes() it exceeding the Field Length
    my filed length in the database is Binary (16)
    Plz do the needful
    Thanks for ur Help in advance

    So System.out.println(theString) results in "00033DB7FB87EC4EB371BCC9D3BF13EC"?
    Then .getBytes() is not what you need. It will get the bytes representing this unicode string in a specific encoding (such as ISO-8859-1, UTF-8 or the like).
    You need to parse to digits each as hexadecimal numbers (using Integer.parseInt() for example, don't forget to specify the radix 16) and convert that to a byte[] array (the length of the byte array should be half the size of the String).
    Warning: because Java knows only signed ints, you'll have to jump through some hoops to get the correct value. Assuming String a contains 2 hexadecimal digits, you get the byte value like this:
    byte b = (byte) (Integer.parseInt(a,16) & 0xFF);

  • What are the conversion rules

    what are the conversion rules?can anybody give information on that?points wil be rewarded?

    hI..
    From sap help....
    <b>Conversion Rules for Elementary Data Types</b>
    There are ten predefined ABAP data types. There are 100 possible type combinations between these elementary data types. ABAP supports automatic type conversion and length adjustment for all of them except type D (date) and type T (time) fields which cannot be converted into each other.
    The following conversion tables define the rules for converting elementary data types for all possible combinations of source and target fields.
    C  D  F  I  N  P  STRING  T  X  XSTRING
    Source Type Character
    <b>
    Conversion table for source type C</b>
    Target
    Conversion
    C
    The target field is filled from left to right. If it is too long, it is filled with blanks from the right. If it is too short, the contents are truncated from the right.
    D
    The character field must contain an 8-character date in the format YYYYMMDD .
    F
    The contents of the source field must be a valid representation of a type F field as described in Literals.
    N
    Only the digits in the source field are copied. The field is right-justified and filled with trailing zeros.
    I, P
    The source field must contain the representation of a decimal number, that is, a sequence of digits with an optional sign and no more than one decimal point. The source field can contain blanks. If the target field is too short, an overflow may occur. This may cause the system to terminate the program.
    STRING
    The occupied length of the source field is copied. All trailing spaces are truncated.
    T
    The character field must contain a six-character time in HHMMSS format.
    X
    Since the character field must contain a hexadecimal string, the only valid characters are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. This string is packed as a hexadecimal number, transported left-justified, and filled with zeros or truncated on the right.
    XSTRING
    As for fields of type X, except that the target field is not filled with zeros.
    <b>Source Type Date</b>
    <b>Conversion table for source type D</b>
    <b>Target
    Conversion</b>
    C
    The date is transported left-justified without conversion.
    D
    Transport without conversion.
    F
    The date is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).
    N
    The date is transported left-justified without conversion and, if necessary, filled with zeros on the right.
    I, P
    The date is converted to the number of days since 01.01.0001.
    STRING
    The date is converted to a character field, which is then converted to a character string.
    T
    Not supported. Results in an error message during the syntax check or in a runtime error.
    X
    The date is converted to the number of days since 01.01.0001 in hexadecimal format.
    XSTRING
    As for fields of type X, except that only significant bytes are copied.
    <b>Source Type Floating Point Number
    Conversion table for source type F
    Target
    Conversion</b>
    C
    The floating point number is converted to the <mantissa>E<exponent> format and transported to the character field. The value of the mantissa lies between 1 and 10 unless the number is zero. The exponent is always signed. If the target field is too short, the mantissa is rounded. The length of the character field must be at least 6 bytes.
    D
    The source field is converted into a packed number. The packed number is then converted into a date field (see corresponding table).
    F
    Transport without conversion.
    N
    The source field is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).
    I, P
    The floating point number is converted to an integer or fixed point value and, if necessary, rounded.
    STRING
    As for fields of type C, except that the maximum number of places is used for the mantissa (maximum precision). Despite this, different signs or exponents can lead to different string lengths.
    T
    The source field is converted into a packed number. The packed number is then converted into a time field (see corresponding table).
    X
    The source field is converted into a packed number. The packed number is then converted into a hexadecimal number (see corresponding table).
    XSTRING
    As for fields of type X, except that leading zeros are not copied.
    <b>Source Type Integer</b>
    Type I is always treated in the same way as type P without decimal places. Wherever type P is mentioned, the same applies to type I fields.
    <b>Source Type Numeric Text
    Conversion table for source type N</b>
    <b>Target
    Conversion</b>
    C
    The numeric field is treated like a character field. Leading zeros are retained.
    D
    The numeric field is converted into a character field. The character field is then converted into a date field (see corresponding table).
    F
    The numeric field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).
    N
    The numeric field is transported right-justified and filled with zeros or truncated on the left.
    I, P
    The numeric field is interpreted as a number, and transferred to the target field, where it is right-justified, and adopts a plus sign. If the target field is too short, the program may be terminated.
    STRING
    As for fields of type C. The length of the character string matches the length of the numeric text.
    T
    The numeric field is converted into a character field. The character field is then converted into a time field (see corresponding table).
    X
    The numeric field is converted into a packed number. The packed number is then converted into a hexadecimal number (see corresponding table).
    XSTRING
    As for fields of type X, except that leading zeros are not copied.
    <b>Source Type Packed Number</b>
    If the program attribute Fixed point arithmetic is set, the system rounds type P fields according to the number of decimal places or fills them out with zeros.
    <b>Conversion table for source type P
    Target
    Conversion
    </b>
    C
    The packed field is transported right-justified to the character field, if required with a decimal point. The last position is reserved for the sign. Leading zeros appear as blanks. If the target field is too short, the sign is omitted for positive numbers. If this is still not sufficient, the field is truncated on the left. ABAP indicates the truncation with an asterisk (*). If you want the leading zeros to appear in the character field, use UNPACK instead of MOVE.
    D
    The packed field value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.
    F
    The packed field is accepted and transported as a floating point number.
    N
    The packed field is rounded if necessary, unpacked, and then transported right-justified. The sign is omitted. If required, the target field is filled with zeros on the left.
    I, P
    A packed field is converted to type I. The resulting four bytes are placed into the target field right-justified. If the target field is too short, an overflow occurs. If the target field is longer, it is filled with zeros on the left.
    STRING
    As for fields of type C, except that leading zeros are not generated.
    T
    The packed field value represents the number of seconds since midnight and is converted to a time in HHMMSS format.
    X
    A packed field is converted to type I. The resulting four bytes are placed into the target field right-justified and in big-endian format. If the target field is too short, it is truncated from the left. If the target field is longer than 4, it is filled with zeros on the left. Negative numbers are represented by the two's complement (= bit complement +1).
    XSTRING
    As for fields of type X, except that leading zeros are not generated.
    <b>Source Type String
    Conversion table for source type STRING
    Target
    Conversion</b>
    C
    The target field is filled from left to right. If it is longer than the string, it is filled with trailing spaces. If it is too short, the contents are truncated from the right.
    D
    The string must contain an 8-character date in the format YYYYMMDD .
    F
    The contents of the string must be a valid representation of a type F field as described in Literals.
    N
    Only digits in the string are copied. The field is right-justified and filled with trailing zeros. If the target field is too short, it is truncated from the left.
    I, P
    The string must contain the representation of a decimal number, that is, a sequence of digits with an optional sign and no more than one decimal point. The source field can contain blanks. If the target field is too short, an overflow may occur. This may cause the system to terminate the program.
    STRING
    The source string is copied to the target string unconverted.
    T
    The string must contain a six-character time in HHMMSS format.
    X
    Since the character field must contain a hexadecimal-character string, the only valid characters are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. This character string is packed as a hexadecimal number, transported left-justified, and filled with zeros or truncated on the right.
    XSTRING
    As for target fields of type X, except that the field is not filled with zeros.
    <b>
    Source Type Time
    Conversion table for source type T
    Target
    Conversion</b>
    C
    The source field is transported left-justified without conversion.
    D
    Not supported. Results in an error message during the syntax check or in a runtime error.
    F
    The source field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).
    N
    The date is converted into a character field. The character field is then converted into a numeric text field (see corresponding table).
    I, P
    The date is converted to the number of seconds since midnight.
    STRING
    The time is converted to a character field, which is then converted to a character string.
    T
    The date is transported left-justified without conversion and, if necessary, filled with zeros on the right.
    X
    The date is converted to the number of seconds since midnight in hexadecimal format.
    XSTRING
    As for fields of type X, except that only significant bytes are copied.
    <b>Source Type Hexadecimal Field
    Conversion table for source type X
    Target
    Conversion</b>
    C
    The value in the hexadecimal field is converted to a hexadecimal character string, transported left-justified to the target field, and filled with zeros.
    D
    The source field value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.
    F
    The source field is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).
    N
    The source field is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).
    I, P
    The value of the source field is interpreted as a hexadecimal number. It is converted to a packed decimal number and transported right-justified to the target field. If the hexadecimal field is longer than 4 bytes, only the last four bytes are converted. If it is too short, a runtime error may occur.
    STRING
    As for target fields of type C, except that the field is not filled with zeros. The length of the string is twice the length of the hexadecimal field.
    T
    The source field value represents the number of seconds since midnight and is converted to a time in HHMMSS format.
    X
    The value is transported left-justified and filled with X'00' on the right, if necessary.
    XSTRING
    The hexadecimal field is copied completely – that is, trailing zeros are not truncated.
    Source Type Byte Sequence
    Conversion table for source type XSTRING
    Target
    Conversion
    C
    The value in the byte sequence is converted to a hexadecimal character string, transported left-justified to the target field, and filled with zeros.
    D
    The byte sequence value represents the number of days since 01.01.0001 and is converted to a date in YYYYMMDD format.
    F
    The content of the byte sequence is converted into a packed number. The packed number is then converted into a floating point number (see corresponding table).
    N
    The content of the byte sequence is converted into a packed number. The packed number is then converted into a numeric text field (see corresponding table).
    I, P
    The content of the byte sequence is interpreted as a hexadecimal number. It is converted to a packed decimal number and transported right-justified to the target field. If the byte sequence is longer than 4 bytes, only the last four bytes are converted. If it is too short, a runtime error may occur.
    STRING
    As for target fields of type C, except that the field is not filled with zeros. The length of the string is twice the length of the byte sequence.
    T
    The byte sequence value represents the number of seconds since midnight and is converted to a time in HHMMSS format.
    X
    The byte sequence is transported left-justified and filled with X'00' on the right, if necessary.
    XSTRING
    The source byte sequence is copied to the target byte sequence unconverted.
    Conversion Rules for Internal Tables
    Internal tables can only be converted into other internal tables. You cannot convert them into structures or elementary fields.
    Internal tables are convertible if their line types are convertible. The convertibility of internal tables does not depend on the number of lines.
    <b>Conversion rules for internal tables:</b>
    Internal tables which have internal tables as their line type are convertible if the internal tables which define the line types are convertible.
    Internal tables which have line types that are structures with internal tables as components are convertible according to the conversion rules for structures if the structures are compatible.
    <b>Conversion Rules for Structures</b>
    ABAP has one rule for converting structures that do not contain internal tables as components. There are no conversion rules for structures that contain internal tables. You can only make assignments between structures that are compatible.
    You can combine convertible structures in the following combinations:
    Converting a structure into a non-compatible structure
    Converting elementary fields into structures
    Converting structures into elementary fields
    In each case, the system first converts all the structures concerned to type C fields and then performs the conversion between the two resulting elementary fields. The length of the type C fields is the sum of the lengths of the structure components. This rule applies to all operations using structures that do not contain internal tables.
    If a structure is aligned, the filler fields are also added to the length of the type C field.
    A non-aligned structure without filler fields:
    If you convert a structure into a shorter structure, the original structure is truncated. If you convert a structure into a longer one, the parts at the end are not initialized according to their type, but filled with blanks.
    It can make sense to assign a structure to another, incompatible, structure if, for example, the target structure is shorter than the source, and both structures have the same construction over the length of the shorter structure. However, numeric components of structures that are filled in incompatible assignments may contain nonsensical or invalid values that may cause runtime errors.
    DATA: BEGIN OF FS1,
    INT TYPE I VALUE 5,
    PACK TYPE P DECIMALS 2 VALUE ‘2.26’,
    TEXT(10) TYPE C VALUE ‘Fine text’,
    FLOAT TYPE F VALUE ‘1.234e+05’,
    DATA TYPE D VALUE ‘19950916’,
    END OF FS1.
    DATA: BEGIN OF FS2,
    INT TYPE I VALUE 3,
    PACK TYPE P DECIMALS 2 VALUE ‘72.34’,
    TEXT(5) TYPE C VALUE ‘Hello’,
    END OF FS2.
    WRITE: / FS1-INT, FS1-PACK; FS1-TEXT, FS1-FLOAT, FS1-DATE.
    WRITE: / FS2-INT, FS2-PACK, FS2-TEXT.
    MOVE FS1 TO FS2.
    WRITE: / FS2-INT, FS2-PACK, FS2-TEXT.
    Message was edited by:
            Rammohan Nagam

Maybe you are looking for

  • Music storage

    Hi there,  My music is being stored on my SD card, which is now full. How do I change music storage to be on the phone? Thanks.

  • Where is the WIN 8 serial number? MSI gt70

    I wonder where can I find it? O the recovery with F3 really work? Will I get the WIN 8 back to original state? Need more info Also how to update default drivers? I updated NVIDIA drivers, but what about the rest?

  • SGE2000 slow forwarding as accessswitch with LACP to SG500X stack

    Hello everyone, Question: Does any body know why  ports on my SGE2000 take so long (>60s) before forwarding packets to  the end user systems (desktop computers). I got two SG500X switches stacked in 10G mode and got two SGE2000 switches connected in

  • Script errors in Contribute CS3

    I created a site recently that uses code from Particletree for a Lightbox. ( http://particletree.com/features/lightbox-gone-wild/) When I browse those lightbox pages in Contribute, it throws an IE warning about a JS error and asks me if I want to deb

  • Schedule sequence heuristic

    We are currently on scm 5.1 version. planned orders are generated for a together for multiple sale orders by variable heuristic. start dates will be based on the requirement date of sale order. suddenly the priority changes. the first priority sale o