字符之间的异或运算 [英] xor operation between chars

查看:250
本文介绍了字符之间的异或运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下一段Java代码,并且在Eclipse,Windows 7中调试时,变量'xoredChar'根本没有显示任何值,不是null,不是",什么也没有.

I have the following piece of Java code and while debugging in Eclipse, Windows 7, the variable 'xoredChar' shows no value at all, not null, not '', nothing.

char xoredChar = (char) (stringA.charAt(j)^stringB.charAt(j));

那是为什么?我需要了解如何在java中的两个字符之间执行此xor操作.我想念什么?

Why is that? I need to understand how can I do this xor operation between two characters in java. What am I missing?

推荐答案

好吧,如果字符串相等,则会返回一个 \ 0 ,该字符不是可打印字符.尝试这样的事情,

Well, if the strings are equal you'll get back a \0 which is not a printable character. Try something like this,

String stringA = "A";
String stringB = "A";
int j = 0;
char xoredChar = (char) (stringA.charAt(j) ^ stringB.charAt(j));
System.out.printf("'%c' = %d\n", xoredChar, (int) xoredChar);

输出为

' ' = 0

这篇关于字符之间的异或运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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