Interview questions-use bit operations to implement A+B in ABAP

Source: Internet
Author: User

The fifth integer addition algorithm implemented with ABAP:

Implementation code:

Report Zint. PARAMETERS:A type int4 obligatory default, B type int4 obligatory default 100.data:threshold TYPE int4.  FORM add USING A type int4 b type int4 changing Cv_result type int4.  Data:n type int4 value 0, C type int4 value 0.  DATA:I TYPE int4 VALUE 1.        Data:boolean_a type Abap_bool, Boolean_b type Abap_bool, _a type int4, _b type int4,  AA type Int4, BB type int4.  DATA (Wrapper_one) = zcl_integer=>value_of (1).  DATA (Wrapper_c) = Zcl_integer=>value_of (c).  AA = A.  bb = b.    While I < threshold.    DATA (wrapper_a) = zcl_integer=>value_of (AA).    DATA (Wrapper_b) = zcl_integer=>value_of (BB).    Boolean_a = Boolc (Wrapper_a->and (Wrapper_one)->get_raw_value () EQ 1).    Boolean_b = Boolc (Wrapper_b->and (Wrapper_one)->get_raw_value () EQ 1).    _a = COND int4 (when Boolean_a EQ abap_true then 1 ELSE 0).    _b = COND int4 (when Boolean_b EQ abap_true then 1 ELSE 0). WRapper_a = zcl_integer=>value_of (_a).    Wrapper_b = zcl_integer=>value_of (_b).    Wrapper_c = Zcl_integer=>value_of (c).    DATA (_n_wrapper) = Wrapper_a->xor (Wrapper_b)->xor (wrapper_c).    DATA (B_or_c) = Wrapper_b->or (wrapper_c).    DATA (B_and_c) = Wrapper_b->and (wrapper_c).    DATA (_c_wrapper) = Wrapper_a->and (b_or_c)->or (B_and_c).    c = _c_wrapper->get_raw_value ().    DATA (_n_i0_wrapper) = Zcl_integer=>value_of (COND int4 (when _n_wrapper->get_raw_value () > 0 Then I ELSE 0)).    DATA (Wrapper_n) = Zcl_integer=>value_of (n).    n = wrapper_n->or (_n_i0_wrapper)->get_raw_value ().    wrapper_a = zcl_integer=>value_of (aa).    AA = Wrapper_a->shift_right ()->get_raw_value ().    Wrapper_b = zcl_integer=>value_of (BB).    bb = Wrapper_b->shift_right ()->get_raw_value ().    Cv_result = N.    DATA (Wrapper_i) = Zcl_integer=>value_of (i).    Wrapper_i->shift_left (). i = Wrapper_i->get_rAw_value (). Endwhile. EndForm.  Start-of-selection.  DATA:I TYPE int4.  Threshold = Ipow (base = 2 Exp = 30).  PERFORM Add USING a b changing I. WRITE:/I.

Algorithm description refer to my SCN blog? Just for fun–implement A + b using pure bitwise operation in ABAP

To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:

Interview questions-use bit operations to implement A+B in ABAP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.