HTML过滤和补齐(五)

本文汇总了一系列实用的Java工具方法,包括字符串转数值类型、位运算、字符串比较、MD5与Base64转换等,旨在提供高效简洁的代码实现。
/**
* 转换字符串为long
*
* @param s
* @param def
* @return
*/
public static long getLong(String s, long def) {
long i = def;
try {
i = Long.parseLong(s);
} catch (NumberFormatException e) {
// ignore
}
return i;
}

/**
* 转换字符串为long
*
* @param s
* @return
*/
public static long getLong(String s) {
return getLong(s, 0);
}

/**
* 对整数按位取与
*
* @param a
* @param b
* @return
*/
public static int bitAND(int a, int b) {
return a & b;
}

/**
* 对整数按位取或
*
* @param a
* @param b
* @return
*/
public static int bitOR(int a, int b) {
return a | b;
}

/**
* 对整数按位取异或
*
* @param a
* @param b
* @return
*/
public static int bitXOR(int a, int b) {
return a ^ b;
}

/**
* 判断一个字符串是否在字符数组中出现
*
* @param arr
* @param s
* @return
*/
public static boolean inStrings(String[] arr, String s) {
if (arr != null && s != null && arr.length > 0) {
for (int i = 0; i < arr.length; i++) {
if (s.equals(arr[i])) {
return true;
}
}
}
return false;
}

/**
* 转换字符串为Float
*
* @param s
* @param def
* @return
*/
public static float getFloat(String s, float def) {
float i = def;
try {
i = Float.parseFloat(s);
} catch (NumberFormatException e) {
// ignore
}
return i;
}

/**
* 转换字符串为Float
*
* @param s
* @return
*/
public static float getFloat(String s) {
return getFloat(s, 0);
}

/**
* 把MD5生成的专成Base64,会节省8个字节的空间
*
* @param string
* @return
*/
public static String radix4StringToRadix6String(String string) {
return bytesTo6RadixString(radix4StringToBytes(string));
}

/**
* 把base64的专成标准的MD5表示
*
* @param string
* @return
*/
public static String radix6StringToradix4String(String string) {
return bytesTo4RadixString(radix6StringToBytes(string));
}

/**
* 将MD5生成的byte流,转换成标准的字符输出
*
* @param bs
* @return
*/
public static final String bytesTo4RadixString(byte[] bs) {
int l = bs.length;

char[] out = new char[l << 1];

for (int i = 0, j = 0; i < l; i++) {
out[j++] = digits[(0xF0 & bs[i]) >>> 4];
out[j++] = digits[0x0F & bs[i]];
}

return new String(out);
}

/**
* 将MD5转换过的字符输出还原成byte流
*
* @param string
* @return
*/
public static final byte[] radix4StringToBytes(String string) {
byte[] digesta = null;
if (!isEmpty(string)) {
byte[] tmpBytes = string.getBytes();
digesta = new byte[tmpBytes.length / 2];
for (int i = 0; i < tmpBytes.length; i += 2) {
byte b = cb(tmpBytes[i]);
byte b1 = (i + 1 < tmpBytes.length) ? cb(tmpBytes[i + 1]) : 0;
digesta[i / 2] = (byte) (((b << 4) | b1) & 0xFF);
}
}
return digesta;
}

/**
* = base64decode
*
* @param string
* @return
*/
public static final byte[] radix6StringToBytes(String string) {
return Base64.encodeBase64(string.getBytes());
}

/**
* = base64encode
*
* @param digesta
* @return
*/
public static final String bytesTo6RadixString(byte[] digesta) {
return new String(Base64.encodeBase64(digesta));
}

private static final byte cb(byte b) {
if (b < 58) {
b -= 48;
} else if (b > 96) {
b -= 87;
} else {
b = 0;
}
return (byte) (b & 0x0F);
}
}
带开环升压转换器逆变器的太阳能光伏系统 太阳能光伏系统驱动开环升压转换器SPWM逆变器提供波形稳定、设计简单的交流电的模型 Simulink模型展示了一个完整的基于太阳能光伏的直流到交流电力转换系统,该系统由简单、透明、易于理解的模块构建而成。该系统从配置为提供真实直流输出电压的光伏阵列开始,然后由开环DC-DC升压转换器进行处理。升压转换器将光伏电压提高到适合为单相全桥逆变器供电的稳定直流链路电平。 逆变器使用正弦PWM(SPWM)开关来产生干净的交流输出波形,使该模型成为研究直流-交流转换基本操作的理想选择。该设计避免了闭环MPPT的复杂性,使用户能够专注于光伏接口、升压转换逆变器开关的核心概念。 此模型包含的主要功能: •太阳能光伏阵列在标准条件下产生~200V电压 •具有固定占空比操作的开环升压转换器 •直流链路电容器,用于平滑稳定转换器输出 •单相全桥SPWM逆变器 •交流负载,用于观察实际输出行为 •显示光伏电压、升压输出、直流链路电压、逆变器交流波形负载电流的组织良好的范围 •完全可编辑的结构,适合分析、实验扩展 该模型旨在为太阳能直流-交流转换提供一个干净高效的仿真框架。布局简单明了,允许用户快速了解信号流,检查各个阶段,并根据需要修改参数。 系统架构有意保持模块化,因此可以轻松扩展,例如通过添加MPPT、动态负载行为、闭环升压控制或并网逆变器概念。该模型为进一步开发或整合到更大的可再生能源模拟中奠定了坚实的基础。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值