当前位置: 首页 > news >正文

c# 不同数据类型转换

namespace Systempublic static class ConvertExtension
{public static byte[] ToBinaryByteArray(this byte[] bytes){// 每个字节有 8 位,所以总位数为 bytes.Length * 8byte[] binaryArray = new byte[bytes.Length * 8];int index = 0;// 遍历每个字节foreach (byte b in bytes){// 遍历字节的每一位for (int i = 0; i < 8; i++){byte bit = (byte)(((b >> i) & 1));binaryArray[index++] = bit;}}return binaryArray;}public static int BinaryArrayToDecimal(this byte[] binaryArray){int decimalValue = 0;int length = binaryArray.Length;for (int i = 0; i < length; i++){if (binaryArray[i] == 1){decimalValue += (int)Math.Pow(2, i);}}return decimalValue;}public static IEnumerable<T> ConvertRowMajorToColumnMajor<T>(this IEnumerable<T> rowMajor, int rows, int columns){List<T> columnMajor = new List<T>();for (int col = 0; col < columns; col++){for (int row = 0; row < rows; row++){int index = row * columns + col;if (rowMajor.Count() <= index){break;}columnMajor.Add(rowMajor.ElementAt(index));}}return columnMajor;}public static byte[] SwitchBytes(this byte[] data, int blockSize = 2){if (data == null || data.Length < 2 || data.Length % blockSize != 0){return null;}List<byte> bytes = new List<byte>();for (int i = 0; i < data.Length; i += blockSize){byte[] temp = new byte[blockSize];Array.Copy(data, i, temp, 0, blockSize);bytes.AddRange(temp.Reverse());}return bytes.ToArray();}public static byte[] BytesReverse(this byte[] data){return data?.Reverse().ToArray();}public static string BytesToStr(this byte[] data, Encoding encoding = null){if (encoding == null){return Encoding.Default.GetString(data);}return encoding.GetString(data);}public static byte HexToByte(this string str){str = str.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("0x", "");if (string.IsNullOrEmpty(str)){return 0;}try{return Convert.ToByte(str, 16);}catch (Exception){return 0;}}public static string ByteToHex(this byte data){return Convert.ToString(data, 16).PadLeft(2, '0').ToUpper();}public static string ToHex(this byte data){return Convert.ToString(data, 16).PadLeft(2, '0').ToUpper();}public static byte[] HexToBytes(this object value, bool isReverse = false){return value.ToString().HexToBytes(isReverse);}public static bool[] HexToBoolBinary(byte[] hexBytes){byte[] binaryBytes = new byte[hexBytes.Length * 8];bool[] res = new bool[hexBytes.Length * 8];for (int i = 0; i < hexBytes.Length; i++){byte hexByte = hexBytes[i];for (int j = 0; j < 8; j++){byte binaryBit = (byte)((hexByte >> (7 - j)) & 1);binaryBytes[i * 8 + j] = binaryBit;res[i * 8 + j] = binaryBit == 0 ? false : true;}}return res;}public static byte[] HexToBytes(this string str, bool isReverse = false){if (string.IsNullOrEmpty(str)){return null;}if(str.Length==1){str = str.PadLeft(2, '0');}str = str.Replace(" ", "").Replace("\r", "").Replace("\n", "");if (string.IsNullOrEmpty(str)){return null;}try{byte[] bytes = new byte[str.Length / 2];for (int i = 0; i < bytes.Length; i++){bytes[i] = Convert.ToByte(str.Substring(2 * i, 2), 16);}if (isReverse){bytes = bytes.Reverse().ToArray();}return bytes;}catch (Exception ex){return null;}}public static byte[] StrToBytes(this string str, Encoding encoding = null){str = str.Replace(" ", "").Replace("\r", "").Replace("\n", "");if (string.IsNullOrEmpty(str)){return null;}try{return (encoding == null) ? Encoding.UTF8.GetBytes(str) : encoding.GetBytes(str);}catch (Exception ex){return null;}}public static string ToHex(this byte[] data, string pre, bool isWithSpace = false, bool isReverse = false){if (data == null || data.Length < 1){return null;}try{if (isReverse){data = data.Reverse().ToArray();}StringBuilder sb = new StringBuilder(data.Length * 2);if (isWithSpace){byte[] array = data;foreach (byte b2 in array){sb.Append(Convert.ToString(b2, 16).PadLeft(2, '0').PadLeft(3, ' '));}}else{byte[] array2 = data;foreach (byte b in array2){sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));}}return pre + sb.ToString().ToUpper().Trim();}catch (Exception ex){return null;}}public static byte[] BinaryToHex(byte[] binaryBytes){int hexLength = binaryBytes.Length / 8;byte[] hexBytes = new byte[hexLength];for (int i = 0; i < hexLength; i++){byte hexByte = 0;for (int j = 0; j < 8; j++){byte binaryBit = binaryBytes[i * 8 + j];hexByte = (byte)((hexByte << 1) | binaryBit);}hexBytes[i] = hexByte;}return hexBytes;}public static string ToHex(this byte[] data, bool isWithSpace = false, string pre = null, bool isReverse = false){if (data == null || data.Length < 1){return null;}try{if (isReverse){data = data.Reverse().ToArray();}StringBuilder sb = new StringBuilder(data.Length * 2);if (isWithSpace){byte[] array = data;foreach (byte b2 in array){sb.Append(Convert.ToString(b2, 16).PadLeft(2, '0').PadLeft(3, ' '));}}else{byte[] array2 = data;foreach (byte b in array2){sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));}}return pre + sb.ToString().ToUpper().Trim();}catch (Exception ex){return null;}}public static string ToStr(this byte[] data, Encoding encoding = null){if (data == null || data.Length < 1){return null;}try{return (encoding == null) ? Encoding.UTF8.GetString(data) : encoding.GetString(data);}catch (Exception ex){return null;}}public static byte[] IntToBytes(this object value){if (value == null){return null;}try{int temp = Convert.ToInt32(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] IntToBytes(this int value){return BitConverter.GetBytes(value);}public static int ToInt(this byte[] bytes){if (bytes == null || bytes.Length < 4){return 0;}return BitConverter.ToInt32(bytes, 0);}public static int ToInt(this byte[] bytes, int index){if (bytes == null || bytes.Length < 4 || index < 0 || index + 4 > bytes.Length){return 0;}byte[] result = new byte[4];Array.Copy(bytes, index, result, 0, 4);return BitConverter.ToInt32(result, 0);}public static byte[] UintToBytes(this object value){if (value == null){return null;}try{uint temp = Convert.ToUInt32(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] UintToBytes(this uint value){return BitConverter.GetBytes(value);}public static uint ToUint(this byte[] bytes){if (bytes == null || bytes.Length < 4){return 0u;}return BitConverter.ToUInt32(bytes, 0);}public static uint ToUint(this byte[] bytes, int index){if (bytes == null || index < 0 || index + 4 > bytes.Length){return 0u;}byte[] result = new byte[4];Array.Copy(bytes, index, result, 0, 4);return BitConverter.ToUInt32(result, 0);}public static byte[] ShortToBytes(this object value){if (value == null){return null;}try{short temp = Convert.ToInt16(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] ShortToBytes(this short value){return BitConverter.GetBytes(value);}public static short ToShort(this byte[] bytes){if (bytes == null || bytes.Length < 2){return 0;}return BitConverter.ToInt16(bytes, 0);}public static short ToShort(this byte[] bytes, int index){if (bytes == null || bytes.Length < 2 || index < 0 || index + 2 > bytes.Length){return 0;}byte[] result = new byte[2];Array.Copy(bytes, index, result, 0, 2);return BitConverter.ToInt16(result, 0);}public static byte[] UshortToBytes(this object value){if (value == null){return null;}try{ushort temp = Convert.ToUInt16(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] UshortToBytes(this ushort value, bool isReverse = false){byte[] result = BitConverter.GetBytes(value);if (isReverse){Array.Reverse(result);}return result;}public static ushort ToUshort(this byte[] bytes){if (bytes == null || bytes.Length < 2){return 0;}return BitConverter.ToUInt16(bytes, 0);}public static ushort ToUshort(this byte[] bytes, int index){if (bytes == null || bytes.Length < 2 || index < 0 || index + 2 > bytes.Length){return 0;}byte[] result = new byte[2];Array.Copy(bytes, index, result, 0, 2);return BitConverter.ToUInt16(result, 0);}public static byte[] FloatToBytes(this object value){if (value == null){return null;}try{float temp = Convert.ToSingle(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] FloatToBytes(this float value){return BitConverter.GetBytes(value);}public static float ToFloat(this byte[] bytes, bool isReverse = false){if (isReverse && bytes != null){Array.Reverse(bytes);}return (bytes == null) ? 0f : BitConverter.ToSingle(bytes, 0);}public static float ToFloat(this byte[] bytes, int index){if (bytes == null || bytes.Length < 4 || index < 0 || index + 4 > bytes.Length){return 0f;}byte[] result = new byte[4];Array.Copy(bytes, index, result, 0, 4);return BitConverter.ToSingle(result, 0);}public static byte[] DoubleToBytes(this object value){if (value == null){return null;}try{double temp = Convert.ToDouble(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] DoubleToBytes(this double value){return BitConverter.GetBytes(value);}public static double ToDouble(this byte[] bytes){return BitConverter.ToDouble(bytes, 0);}public static double ToDouble(this byte[] bytes, int index){if (bytes == null || bytes.Length < 8 || index < 0 || index + 8 > bytes.Length){return 0.0;}byte[] result = new byte[8];Array.Copy(bytes, index, result, 0, 8);return BitConverter.ToDouble(result, 0);}public static byte[] LongToBytes(this object value){if (value == null){return null;}try{long temp = Convert.ToInt64(value);return BitConverter.GetBytes(temp);}catch{return null;}}public static byte[] LongToBytes(this long value){return BitConverter.GetBytes(value);}public static long ToLong(this byte[] bytes){return (bytes == null) ? 0 : BitConverter.ToInt64(bytes, 0);}public static byte[] ToBytes(this BitArray value){if (value == null || value.Length == 0){return null;}int conutBase = value.Length / 8;int mod = ((value.Length % 8 != 0) ? 1 : 0);byte[] result = new byte[conutBase + mod];value.CopyTo(result, 0);return result;}public static BitArray ToBitArray(this byte[] bytes){if (bytes == null || bytes.Length == 0){return null;}return new BitArray(bytes);}public static byte ToByte(this BitArray value){if (value == null || value.Length == 0){return 0;}int conutBase = value.Length / 8;int mod = ((value.Length % 8 != 0) ? 1 : 0);byte[] result = new byte[conutBase + mod];value.CopyTo(result, 0);return result[0];}public static BitArray ToBitArray(this byte data){return new BitArray(new byte[1] { data });}public static byte[] GetBits(this byte[] oriData, byte index, byte bitCount){if (oriData == null || bitCount > oriData.Length * 8){return null;}BitArray sourceArray = oriData.ToBitArray();BitArray targetArray = new BitArray(bitCount);for (byte i = 0; i < bitCount; i++){targetArray[i] = sourceArray[index + i];}return targetArray.ToBytes();}public static byte[] SetBits(this byte[] oriData, byte index, byte bitCount, byte[] data){if (oriData == null){return null;}if (data == null || index + bitCount > oriData.Length * 8 || bitCount > data.Length * 8){return oriData;}BitArray sourceArray = data.ToBitArray();BitArray targetArray = oriData.ToBitArray();for (byte i = 0; i < bitCount; i++){targetArray[index + i] = sourceArray[i];}return targetArray.ToBytes();}public static byte GetBits(this byte oriData, byte index, byte bitCount){if (bitCount == 0 || index + bitCount > 8){return 0;}BitArray sourceArray = oriData.ToBitArray();BitArray targetArray = new BitArray(bitCount);for (byte i = 0; i < bitCount; i++){targetArray[i] = sourceArray[index + i];}return targetArray.ToByte();}public static byte SetBits(this byte oriData, byte index, byte bitCount, byte data){if (bitCount == 0 || index + bitCount > 8){return oriData;}BitArray sourceArray = data.ToBitArray();BitArray targetArray = oriData.ToBitArray();for (byte i = 0; i < bitCount; i++){targetArray[index + i] = sourceArray[i];}return targetArray.ToByte();}public static void SetBitHigh(this byte[] source, byte byteIndex, byte bitIndex, bool isHigh = true){if (source != null && source.Length > byteIndex && bitIndex <= 7){byte data = source[byteIndex];data = ((!isHigh) ? ((byte)(data & (byte)(~(1 << (int)bitIndex)))) : ((byte)(data | (byte)(1 << (int)bitIndex))));source[byteIndex] = data;}}public static bool BitHigh(this byte[] source, byte byteIndex, byte bitIndex){if (source == null || source.Length <= byteIndex || bitIndex > 7){return false;}return (source[byteIndex] & (1 << (int)bitIndex)) != 0;}public static byte SetBitHigh(this byte data, byte i, bool isHigh = true){if (i > 7){return data;}if (isHigh){return data |= (byte)(1 << (int)i);}return data &= (byte)(~(1 << (int)i));}public static bool BitHigh(this byte data, byte i){return i <= 7 && (data & (1 << (int)i)) != 0;}public static double DataStandardize(this string str, int roundNum = 3){if (string.IsNullOrEmpty(str)){return 0.0;}try{str = str.Replace("\r", "").Replace("\n", "").Replace(" ", "");if (string.IsNullOrEmpty(str)){return 0.0;}double val;if (str.Contains('E')){string[] strArr = str.Split('E');string baseStr = strArr[0];double baseVal = Convert.ToDouble(baseStr);string powerStr = strArr[1];double powerVal = Convert.ToInt32(powerStr);val = Math.Pow(10.0, powerVal) * baseVal;}else{val = Convert.ToDouble(str);}return Math.Round(val, roundNum);}catch (Exception){return 0.0;}}
}

字节数组与二进制相关转换

  • ToBinaryByteArray方法
    将输入的字节数组转换为表示其每一位的二进制字节数组,每个字节按位展开为8个二进制位存储在新的字节数组中。

  • BinaryArrayToDecimal方法
    把二进制字节数组转换为十进制整数,通过对二进制位对应的2的幂次进行累加来实现转换。

  • BinaryToHex方法
    将二进制字节数组转换为十六进制字节数组,按照一定的位运算规则将8位一组的二进制转换为十六进制表示。

不同数据类型与字节数组相互转换

  • 整数类型相关转换
    • IntToBytes(两个重载方法)
      • 可将int类型值或者object类型(实际能转换为int的对象)转换为字节数组,利用BitConverter.GetBytes方法来实现。
    • ToInt(两个重载方法)
      • 从字节数组中提取数据转换为int类型整数,根据字节数组长度及指定索引情况获取相应数据并转换。
    • UintToBytes(两个重载方法)
      • 针对无符号uint类型,能将uint值或可转换为uintobject转换为字节数组,同样借助BitConverter.GetBytes
    • ToUint(两个重载方法)
      • 把字节数组中的数据转换为无符号uint类型整数,考虑字节数组的合法性和索引范围进行转换。
  • 短整型相关转换
    • ShortToBytes(两个重载方法)
      • 可将short类型值或者能转换为shortobject转换为字节数组,使用BitConverter.GetBytes操作。
    • ToShort(两个重载方法)
      • 从字节数组中获取数据并转换为short类型整数,对字节数组的长度和索引做校验来确保转换正确。
    • UshortToBytes(两个重载方法)
      • 针对无符号ushort类型,能把ushort值或对应的object转换为字节数组,可选择是否反转字节顺序。
    • ToUshort(两个重载方法)
      • 将字节数组中的内容转换为无符号ushort类型整数,依据字节数组条件来执行转换。
  • 浮点型相关转换
    • FloatToBytes(两个重载方法)
      • float类型值或者可转换为floatobject转换为字节数组,借助BitConverter.GetBytes实现转换。
    • ToFloat(两个重载方法)
      • 从字节数组提取数据转换为float类型浮点数,支持根据是否反转字节顺序进行相应处理。
    • DoubleToBytes(两个重载方法)
      • 用于将double类型值或者能转换为doubleobject转换为字节数组,调用BitConverter.GetBytes
    • ToDouble(两个重载方法)
      • 从字节数组中获取数据并转换为double类型双精度浮点数,会校验字节数组长度和索引范围。
  • 长整型相关转换
    • LongToBytes(两个重载方法)
      • 可把long类型值或者可转换为longobject转换为字节数组,依靠BitConverter.GetBytes进行转换。
    • ToLong方法
      • 从字节数组中读取数据并转换为long类型长整数。

字节数组顺序相关转换

  • SwitchBytes方法
    按照指定的块大小(默认块大小为2)对字节数组中的数据块进行反转顺序操作,例如每2个字节一组进行反转。

  • BytesReverse方法
    直接对整个字节数组进行反转顺序的操作,返回反转后的字节数组。

字节数组与字符串相关转换

  • BytesToStr方法
    将字节数组转换为字符串,如果未指定编码则使用默认编码(Encoding.Default)进行转换,也可指定编码来转换。

  • StrToBytes方法
    把输入的字符串转换为字节数组,先对字符串做去除空白字符等预处理,若未指定编码则使用UTF8编码进行转换,否则按指定编码转换。

十六进制相关转换

  • HexToByte方法
    把十六进制表示的字符串(可包含或去除如0x、空格、换行、回车等格式相关字符)转换为字节类型,若转换失败则返回0。

  • ByteToHex方法
    将字节类型数据转换为十六进制表示的字符串,进行格式化为固定长度并转换为大写形式。

  • ToHex(多个重载方法)

    • 可将字节或字节数组转换为十六进制表示的字符串,支持添加前缀、是否带空格间隔以及是否反转字节顺序等多种格式控制。
  • HexToBytes(多个重载方法)

    • 能把十六进制表示的字符串或者对象(通过其ToString方法后的字符串)转换为字节数组,可选择是否反转字节顺序,处理各种字符串格式异常情况。

布尔值与十六进制、二进制相关转换

  • HexToBoolBinary方法
    将十六进制字节数组转换为布尔值数组,先把十六进制字节按位转换为二进制字节,再进一步转换为布尔值数组(0对应false,1对应true)。

位操作相关转换

  • ToBitArray(两个重载方法)
    • 可将字节数组或者字节类型数据转换为BitArray类型,用于后续的位操作相关处理。
    • 从字节数组或单个字节创建对应的BitArray实例。
  • ToBytes(两个重载方法)
    • BitArray类型数据转换为字节数组,根据BitArray的长度情况进行字节数组的构建与赋值。
    • BitArray获取字节数组表示,考虑长度是否为8的倍数等情况。
  • GetBits(多个重载方法)
    • 从字节数组或者单个字节中按照指定的起始位索引和获取的位数,提取相应的位数据并转换为字节数组或字节类型返回。
  • SetBits(多个重载方法)
    • 对字节数组或者单个字节在指定的起始位索引和位数范围内,用给定的数据设置相应的位,返回更新后的字节数组或字节类型。
  • SetBitHigh(多个重载方法)
    • 针对字节数组或者单个字节,可设置指定字节位置和位索引处的位为高电平(置1)或低电平(置0),并返回更新后的字节数组或字节类型。
  • BitHigh(多个重载方法)
    • 检查字节数组或者单个字节在指定字节位置和位索引处的位是否为高电平(即是否为1),返回布尔值表示结果。

数据标准化相关转换

  • DataStandardize方法
    对输入的字符串进行处理,去除空白字符等,将科学计数法表示或普通数字表示的字符串转换为标准化的双精度浮点数,可指定保留的小数位数进行四舍五入。

二维数组行列转换相关转换

  • ConvertRowMajorToColumnMajor方法
    将按行优先顺序排列的可枚举元素集合转换为按列优先顺序排列的集合,需要指定行数和列数来进行转换操作,返回转换后的列优先顺序的集合。

相关文章:

c# 不同数据类型转换

namespace Systempublic static class ConvertExtension {public static byte[] ToBinaryByteArray(this byte[] bytes){// 每个字节有 8 位&#xff0c;所以总位数为 bytes.Length * 8byte[] binaryArray new byte[bytes.Length * 8];int index 0;// 遍历每个字节foreach (b…...

2025.01.15python商业数据分析top2

一、 导入项目 导入项目、准备项目数据 import pandas as pd# 文件路径为python文件位置下的相对路径dwxpd.read_excel("电蚊香套装市场近三年交易额.xlsx") fmfzpd.read_excel("防霉防蛀片市场近三年交易额.xlsx") msmcpd.read_excel("灭鼠杀虫剂市…...

软件信息化平台项目投标技术方案中如何进行项目实施方案以及安全质量方案培训售后方案应急预案的编写?

在软件平台投标技术方案中,项目实施方案、质量管理、安全管理、培训方案、售后服务方案和应急预案等章节至关重要,它们分别从不同角度确保项目的顺利实施、高质量交付、安全稳定运行、用户有效使用、持续服务保障以及应对突发情况的能力。各章节编制要点相互关联、协同作用,…...

目标检测-R-CNN

R-CNN在2014年被提出&#xff0c;算法流程可以概括如下&#xff1a; 候选区域生成&#xff1a;利用选择性搜索(selective search)方法找出图片中可能存在目标的候选区域(region proposal) CNN网络提取特征&#xff1a;对候选区域进行特征提取(可以使用AlexNet、VGG等网络) 目…...

计算机毕业设计PySpark+PyFlink+Hive地震预测系统 地震数据分析可视化 地震爬虫 大数据毕业设计 Hadoop 机器学习 深度学习

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 作者简介&#xff1a;Java领…...

panddleocr-文本检测+文本方向分类+文本识别整体流程

panddleocr-文本检测文本方向分类文本识别整体流程 通过文本检测–>文本方向分类–>文本识别&#xff0c;即可识别出0~360度的旋转文本。 文本检测的最小外接矩形框根据长宽可以看到90度的角度&#xff0c;而再加入文本方向分类就能扩展到180度的角度。...

【物联网技术与应用】实验9:红外遥控实验

实验9 红外遥控实验 【实验介绍】 红外接线头的主要功能为IC化的一种受光元件&#xff0c;其内部是将光电二极管&#xff08;俗称接收管&#xff09;和集成IC共同组合封装而成&#xff0c;其IC设计主要以类比式控制&#xff0c;一般主要接受38KHz的频率的红外线&#xff0c;而…...

青少年编程与数学 02-004 Go语言Web编程 18课题、日志记录

青少年编程与数学 02-004 Go语言Web编程 18课题、日志记录 一、日志记录&#xff08;一&#xff09;目的&#xff08;二&#xff09;内容类型&#xff08;三&#xff09;日志记录的格式 二、Go Web 日志记录1. 使用标准库 log 包2. 使用 logrus3. 在 Gin 框架中集成 logrus4. 使…...

【数据结构练习题】栈与队列

栈与队列 选择题括号匹配逆波兰表达式求值出栈入栈次序匹配最小栈设计循环队列面试题1. 用队列实现栈。[OJ链接](https://leetcode.cn/problems/implement-stack-using-queues/solutions/)2. 用栈实现队列。[OJ链接](https://leetcode.cn/problems/implement-queue-using-stack…...

ctfshow-web入门-文件包含(web82-web86)条件竞争实现session会话文件包含

目录 1、web82 2、web83 3、web84 4、web85 5、web86 1、web82 新增过滤点 . &#xff0c;查看提示&#xff1a;利用 session 对话进行文件包含&#xff0c;通过条件竞争实现。 条件竞争这个知识点在文件上传、不死马利用与查杀这些里面也会涉及&#xff0c;如果大家不熟…...

前端学习DAY26(华为平板页面)

<!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>平板图片</title><style> .box{text-al…...

【Linux 网络 (三)】:https协议加密解密分析 —— 秘钥协商

网络 一、https协议二 、https相关概念1&#xff09;加密、解密2&#xff09; 常见加密方式&#xff08;对称加密和非对称加密&#xff09;对称加密非对称加密 3&#xff09;数据摘要 && 数据指纹4&#xff09;数字签名 三、HTTPS 的⼯作过程探究1&#xff09;只使⽤对…...

c 保存 csv格式的文件

在C语言中保存数据为CSV&#xff08;逗号分隔值&#xff09;格式的文件&#xff0c;你可以使用标准I/O库函数&#xff0c;如fprintf&#xff0c;来将数据写入文件&#xff0c;并确保每个字段之间用逗号分隔。以下是一个简单的示例&#xff0c;说明如何在C语言中创建一个CSV文件…...

数据结构---------二叉树前序遍历中序遍历后序遍历

以下是用C语言实现二叉树的前序遍历、中序遍历和后序遍历的代码示例&#xff0c;包括递归和非递归&#xff08;借助栈实现&#xff09;两种方式&#xff1a; 1. 二叉树节点结构体定义 #include <stdio.h> #include <stdlib.h>// 二叉树节点结构体 typedef struct…...

【JavaEE】网络(6)

一、http相关概念 1.1 什么是http协议 http协议&#xff08;超文本传输协议&#xff09;&#xff0c;是应用层的一个协议 1.2 应用场景 网页与服务器之间交互手机app与服务器之间交互 http协议是典型的一问一答模式的协议&#xff0c;即请求和响应是一一对应的 二、http协议…...

什么是单例模式

单例模式就是 只有一个 不能存在多个 饿汉式单例模式 实现方式&#xff1a; 这种模式在程序启动或单例类被加载时就创建好实例。例如&#xff0c;以下是一个简单的 C 实现的饿汉式单例类&#xff0c;用于记录日志&#xff08;假设这个日志类在整个程序中有且仅有一个实例&#…...

protobuf实用教程

引言 protobuf安装 protobuf数据类型 基本数据类型 复合类型 Map类型 protobuf使用教程 编写.proto文件 编译 使用 序列化与反序列化 结语 引言 protobuf 是 google 的一种数据交换的格式&#xff0c;它独立于平台语言。 google 提供了 protobuf 多种语言的实现&am…...

人工智能ACA(五)--深度学习基础

一、深度学习概述 1. 深度学习概念 1-1. 深度学习基本概念 深度学习是机器学习的一个分支基于人工神经网络&#xff08;模仿人脑结构&#xff09;通过多层网络自动学习特征能够处理复杂的模式识别问题 1-2. 深度学习的优点与缺点 优点 强大的特征学习能力可以处理复杂问题…...

用python ollama qwen2.5 开发一个AI修仙游戏

用 Python Ollama (Qwen2.5) 开发一个 AI 修仙游戏 简介 本文将介绍如何使用 Python 和 Ollama (Qwen2.5 模型) 开发一个文字版修仙游戏。这个游戏具有以下特点&#xff1a; 完整的修仙世界观和成长体系基于 AI 生成的动态剧情和事件丰富的物品系统(功法、丹药、灵宝等)社交…...

tts语音合成相关开源项目试用对比

chatTTS 如下图所示&#xff0c;在不添加Sample Audio和Text的时候可以正常完成文本转语音&#xff0c;可以自定义添加语气词&#xff0c;笑声和停顿等。 无法实现声音克隆&#xff0c;即模仿某人的音色生成语音。 试用了chatTTS官网推荐的https://voicv.com/voice-cloning进行…...

基于JAVA_JSP电子书下载系统的设计与实现【源码+文档+部署讲解】

目 录 第1章 绪论 课题的研究背景、内容和意义 第2章 主要技术概述 2.1 B/S结构 2.2 JSP技术 2.2.1 JSP技术的强势 2.2.2 JSP技术的弱势 2.3 SQL Server 2000数据库 2.4 JDBC数据库连接 2.4.1 JDBC接口 2.4.2 JDBC的驱动程序 2.5 TOMCAT应用服务器 第3章 需求分…...

外连接转AntiJoin的应用场景与限制条件 | OceanBase SQL 查询改写系列

在《SQL 改写系列&#xff1a;外连接转内连接的常见场景与错误》一文中&#xff0c;我们了解到谓词条件可以过滤掉连接结果中的 null 情形的&#xff0c;将外连接转化为内连接的做法是可行的&#xff0c;正如图1中路径(a)所示。此时&#xff0c;敏锐的你或许会进一步思考&#…...

35道面向初中级前端的基础面试题

新鲜出炉的8月前端面试题 跨域资源共享 CORS 阮一峰 3. JSONP 是什么&#xff1f; 这是我认为写得比较通俗易懂的一篇文章jsonp原理详解——终于搞清楚jsonp是啥了。 4. 事件绑定的方式 嵌入dom 按钮 直接绑定 btn.onclick function(){} 事件监听 btn.addEventList…...

自动驾驶控制算法-横向误差微分方程LQR前馈控制

本文是学习自动驾驶控制算法第六讲 前馈控制与航向误差以及前两节的学习笔记。 1 横向误差微分方程 以规划的轨迹作为自然坐标系&#xff0c;计算自车在轨迹上的投影点&#xff0c;进而计算误差&#xff1a; 如图所示&#xff0c;横向误差为 d d d&#xff0c;航向误差为 θ…...

灭屏情况下,飞行模式+静音模式+插耳,播放音乐,电流异常

1. 功耗现象 灭屏情况下&#xff0c;飞行模式静音模式插耳&#xff0c;播放音乐&#xff0c;电流异常 1.1测试数据 飞行模式静音模式插耳机 原生音乐播放器 DriverOnly 32.5mA User版本 45mA 1.2 电流波形现象 上述看怀疑 CPU 未进入 Deep idle 导致&#xff1f; 2. …...

jsp | servlet | spring forEach读取不了对象List

导致这个问题的原因有很多的&#xff0c;这里讲到的只是原因之一 原因 taglib不认识forEach 解决办法 添加<% taglib uri"http://java.sun.com/jsp/jstl/core" prefix"c" %> &#xff08;我忘写这个东西了哈哈哈&#xff09;...

Taro小程序开发性能优化实践

我们团队在利用Taro进行秒送频道小程序的同时&#xff0c;一直在探索性能优化的最佳实践。随着需求的不断迭代&#xff0c;项目中的性能问题难免日积月累&#xff0c;逐渐暴露出来影响用户体验。适逢双十一大促&#xff0c;我们趁着这个机会统一进行了Taro性能优化实践&#xf…...

数据结构:栈(顺序栈)

目录 1.栈的定义 2.栈的结构 3.栈的接口 3.1初始化 3.2栈的销毁 3.3压栈 3.4判断栈是否为空 3.5出栈 3.6得到栈顶元素 3.7栈的大小 1.栈的定义 栈&#xff1a;一种特殊的线性表&#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端…...

【Maven】Maven的快照库和发行库

1、分类 Maven 支持两种类型的仓库&#xff1a;快照库&#xff08;Snapshot Repository&#xff09;和发行库&#xff08;Release Repository&#xff09;&#xff0c;用于存储不同性质的构件&#xff08;Artifacts&#xff09;。 (1) 快照库 (Snapshot Repository)&#xff…...

如何给负载均衡平台做好安全防御

在现代网络架构中&#xff0c;负载均衡&#xff08;Load Balancing&#xff09;扮演着至关重要的角色。它不仅负责将流量分配到多个服务器以确保高效的服务交付&#xff0c;还作为第一道防线来抵御外部攻击。为了保护您的应用程序和服务免受潜在威胁&#xff0c;必须对负载均衡…...

AI应用-本地模型实现AI生成PPT(简易版)

文章目录 前言技术栈效果展示 一、实现思路二、实现步骤1.本地安装marp-cli2.后端实现3.前端实现 三、代码地址及说明 前言 在许多项目中&#xff0c;生成 PPT 是常见的需求&#xff0c;尤其在教育和报告展示中。传统的生成 PPT 的方法需要手动创建&#xff0c;而使用生成模型…...

JavaScript 数组方法完整指南

JavaScript 数组方法完整指南 1. 数组操作方法 1.1 添加/删除元素 push() 用途: 在数组末尾添加一个或多个元素返回值: 新数组的长度 const fruits [apple, banana]; const newLength fruits.push(orange, grape); console.log(fruits); // [apple, banana, orange, gra…...

基于自定义注解与 AOP 切面实现接口日志全面数据库存储

基于自定义注解与 AOP 切面实现接口日志全面数据库存储 一、引言 在当今复杂的软件系统开发与运维过程中&#xff0c;详细且精准地记录接口的各项信息对于系统性能监测、问题排查、安全审计以及业务分析都有着极为关键的意义。本文将深入讲解如何运用自定义注解与 AOP&#x…...

xcode15 报错 does not contain ‘libarclite‘

新建pod私有库 在xcode15 无法运行 报错 SDK does not contain libarclite at the path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a; try increasing the minimum deployment target 下载 资源文件…...

c# 实现一个简单的异常日志记录(异常迭代+分片+定时清理)+AOP Rougamo全局注入

1. 日志目录和文件管理 日志目录&#xff1a;日志文件存储在 ./Exceptions 目录下。日志文件命名&#xff1a;日志文件的命名格式为 yyyy_MM_dd.log&#xff0c;表示当天的日期。如果当天的日志文件大小超过 maxFileSizeBytes&#xff08;3KB&#xff09;&#xff0c;则会创建…...

python 定时任务管理封装

主逻辑代码 # -*- coding: utf-8 -*- # import apscheduler import pandas as pd from datetime import datetime # 导入调度器&#xff0c;此处使用BackgroundScheduler阻塞调度器 from apscheduler.schedulers.background import BackgroundScheduler # 导入触发器&#xf…...

GIS数据处理/程序/指导,街景百度热力图POI路网建筑物AOI等

简介其他数据处理/程序/指导&#xff01;&#xff01;&#xff01;&#xff08;1&#xff09;街景数据获取&#xff08;2&#xff09;街景语义分割后像素提取&#xff0c;指标计算代码&#xff08;绿视率&#xff0c;天空开阔度、视觉熵/景观多样性等&#xff09;&#xff08;3…...

【落羽的落羽 C语言篇】自定义类型——结构体

文章目录 一、结构体1. 结构体类型的概念和声明2. 结构体变量的创建和初始化3. 结构体成员的访问3.1 直接访问3.2 间接访问 4. 结构体的内存对齐4.1 内存对齐的规则4.2 内存对齐的原因4.3 修改默认对齐数 5. 结构体传参6. 结构体实现位段 在C语言中&#xff0c;已经提供了一些基…...

【WPS安装】WPS编译错误总结:WPS编译失败+仅编译成功ungrib等

WPS编译错误总结&#xff1a;WPS编译失败仅编译成功ungrib等 WPS编译过程问题1&#xff1a;WPS编译失败错误1&#xff1a;gfortran: error: unrecognized command-line option ‘-convert’; did you mean ‘-fconvert’?解决方案 问题2&#xff1a;WPS编译三个exe文件只出现u…...

【Python入门】文件读写

文章一览 一、什么是文件二、文件形态三、文件组成要素四、文件操作五、文件路径六、文件读写操作6.1 文件打开模式6.2 文件的打开6.3 正确关闭文件6.3.1 读文件方法6.3.2 写文件 七、CSV 文件读取7.1 CSV 数据存储格式7.2 CSV 文件特点7.3 使用记事本创建 CSV 文件7.4 用 csv …...

基于变异策略的模糊测试:seed与mutation的含义

1. 引入 最早期的模糊测试&#xff08;fuzz&#xff09;&#xff0c;是生成一些随机的文本序列&#xff0c;对unix系统的命令行输入进行测试。这种古老的方式&#xff0c;也发现了不少漏洞。 但完全随机的fuzz&#xff0c;存在如下问题&#xff1a; &#xff08;1&#xff09…...

制造研发企业与IPD管理体系

芯片/半导体/制造研发型企业&#xff0c;大都知道华为使用过的IPD管理体系&#xff0c;但大家用到什么程度&#xff0c;那就是参差不齐了。 因为IPD管理体系它只是一个管理理念&#xff0c;是一个方法论。它需要有相应的组织架构来承载&#xff0c;它有很复杂的流程需要有IT系统…...

电子应用设计方案68:智能晾衣架系统设计

智能晾衣架系统设计 一、引言 智能晾衣架作为智能家居的一部分&#xff0c;为用户提供了更便捷、高效和舒适的衣物晾晒体验。本设计方案旨在打造一款功能丰富、性能稳定且易于操作的智能晾衣架系统。 二、系统概述 1. 系统目标 - 实现晾衣架的自动升降&#xff0c;方便衣物的…...

如何实现圆形头像功能

文章目录 1 概念介绍2 使用方法3 示例代码我们在上一章回中介绍了Stack Widget,本章回中将介绍CircleAvatar这种Widget,闲话休提,让我们一起Talk Flutter吧。 1 概念介绍 在上一回中我们使用了CircleAvatar Widget,之前也没有介绍过此Widget,因此有些看官希望对它做一些介绍…...

【python自动化六】UI自动化基础-selenium的使用

selenium是目前用得比较多的UI自动化测试框架&#xff0c;支持java&#xff0c;python等多种语言&#xff0c;目前我们就选用selenium来做UI自动化。 1.selenium安装 安装命令 pip install selenium2.selenium的简单使用 本文以chrome浏览器为例&#xff0c;配套selenium中c…...

时间复杂度和空间复杂度理解

空间复杂度和时间复杂度是算法分析中两个重要的概念&#xff0c;用于评估算法的性能。在前端 JavaScript 中&#xff0c;时间复杂度用于评估算法在最坏情况下的运行时间&#xff1b;空间复杂度描述了算法在执行过程中所需的内存空间的增长率&#xff0c;它包括算法所需的临时空…...

详细解读sedex验厂

SEDEX验厂&#xff0c;即供货商商业道德信息交流认证&#xff08;Supplier Ethical Data Exchange&#xff09;&#xff0c;是一种表明企业遵守商业道德的认证。以下是对SEDEX验厂的详细解读&#xff1a; 一、SEDEX验厂概述 SEDEX是一家总部位于英国伦敦的非营利组织&#xf…...

IOT、MES、WMS、MOM 和 EPMS 系统综合技术与业务文档

IOT、MES、WMS、MOM 和 EPMS 系统综合技术与业务文档 一、引言 在现代制造业和工业管理领域&#xff0c;IOT&#xff08;物联网&#xff09;、MES&#xff08;制造执行系统&#xff09;、WMS&#xff08;仓库管理系统&#xff09;、MOM&#xff08;制造运营管理系统&#xff…...

ESP32S3 使用LVGL驱动LCD屏(ST7789主控)

ESP32S3 使用LVGL驱动LCD屏&#xff08;ST7789主控&#xff09; 目录 1 分析原理图 2 驱动、点亮LCD(ST7789) 2.1 在工程中添加目录、文件 2.2 添加esp_lvgl_port组件 2.3 对工程进行必要的配置 2.4 编写必要代码 3 烧录、验证 1 分析原理图 要使用SOC驱动LCD屏&#…...

Zed调试宏 C语言错误日志 异常错误调试信息

1、C中的错误码 在C语言中通过返回错误码或设置全局的errno值来反馈错误问题。errno.h是一个头文件&#xff0c;它定义了一个全局变量errno&#xff0c;用于在程序中记录和报告错误的原因。这个机制主要用于处理系统调用或标准库函数出错时的错误反馈。当系统调用或库函数…...