如何使用! Scala中的运算符? [英] How to use the ! operator in scala?

查看:121
本文介绍了如何使用! Scala中的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是scala的新手,并且正在尝试一些基本操作来掌握这种语言.

I am new to scala and was trying a few basic operations to get a hang of the language.

我正在尝试使用逻辑运算符.例如:

I am trying to use the logical operators. For example :

 val a2 = 0x01&0xFF
 println(!a2)

我要取反a2的值,然后将其打印出来.但这给了我一个错误

I want to negate the value of a2 and then print it out. But it gives me an error saying

value unary_! is not a member of Int

我不确定如何使用NOt运算符.有人可以帮我吗?

I am not sure on how do I use the NOt operator. Could somebody help me?

推荐答案

使用按位而非运算符~.

val a2 = 0x01&0xFF
println(~a2)

检查当然,这是假设您要按位取反值,否则请使用-.

Of course, this is assuming you want to negate the value bitwise, otherwise use -.

这篇关于如何使用! Scala中的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆