Why convert the right operator and Java in SWIFT to get the difference result

I am trying to convert my code from java to swift, but when using the Int type to execute the shift right operator, I get 2 diffrence results.

// java

int d = 25;
int x = d >> 1 + 1;
System.out.println(x) ; //output: 6

// swift(4)

let d = 25
let x = d >> 1 + 1
print(x) //output: 13

What is a quick code solution?

Java is calculating

 d >> (1+1)

This is 6.

Swift is calculating

(d >> 1 ) + 1

This is 13.

You can use parentheses to specify the calculation to be performed.

This is because the operator takes precedence:

< p>> in Swift –
https://developer.apple.com/documentation/swift/operator_declarations – <> in Java – https://docs.oracle.com/javase/ tutorial/java/nutsandbolts/operators.html – before <<

I tried to convert my code from java to swift, but when using the Int type to execute the shift right operator When, get 2 diffrence results.

// java

int d = 25;
int x = d> > 1 + 1;
System.out.println(x); //output: 6

// swift(4)

 let d = 25
let x = d >> 1 + 1
print(x) //output: 13

What is a fast code solution?

Java is calculating

d >> (1+1)

This is 6.

Swift is calculating

(d >> 1) + 1

This is 13.

You can use parentheses to specify the calculation to be performed.

This is because the operator takes precedence:

>In Swift –
https: //developer.apple.com/documentation/swift/operator_declarations – << come before.
> in Java – https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html – before< <

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4144 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.