当前位置: 首页> 娱乐> 影视 > 中国企业排行榜_建筑公司网址_手机百度高级搜索_刚刚济南发通知

中国企业排行榜_建筑公司网址_手机百度高级搜索_刚刚济南发通知

时间:2025/7/19 1:52:49来源:https://blog.csdn.net/C6666888/article/details/144728854 浏览次数:0次
中国企业排行榜_建筑公司网址_手机百度高级搜索_刚刚济南发通知

前四期

字符编码(四)-CSDN博客

实现二进制、八进制、十进制、十六进制互换转换:

Java编码转换

import java.util.Scanner;
public class Main {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("欢迎使用进制转换工具!");while (true) {System.out.println("请选择要转换的进制类型:");System.out.println("1. 二进制转其他");System.out.println("2. 十进制转其他");System.out.println("3. 八进制转其他");System.out.println("4. 十六进制转其他");System.out.println("5. 退出");int choice = scanner.nextInt();if (choice == 5) {break;}System.out.println("请输入要转换的数值:");String input = scanner.next();switch (choice) {case 1:binaryToOthers(input);break;case 2:decimalToOthers(Integer.parseInt(input));break;case 3:octalToOthers(input);break;case 4:hexToOthers(input);break;default:System.out.println("无效的选择,请重新选择!");}}scanner.close();System.out.println("感谢使用本工具!");}private static void binaryToOthers(String binary) {int decimal = Integer.parseInt(binary, 2);System.out.println("二进制 " + binary + " 转换为十进制: " + decimal);System.out.println("二进制 " + binary + " 转换为八进制: " + Integer.toOctalString(decimal));System.out.println("二进制 " + binary + " 转换为十六进制: " + Integer.toHexString(decimal).toUpperCase());}private static void decimalToOthers(int decimal) {System.out.println("十进制 " + decimal + " 转换为二进制: " + Integer.toBinaryString(decimal));System.out.println("十进制 " + decimal + " 转换为八进制: " + Integer.toOctalString(decimal));System.out.println("十进制 " + decimal + " 转换为十六进制: " + Integer.toHexString(decimal).toUpperCase());}private static void octalToOthers(String octal) {int decimal = Integer.parseInt(octal, 8);System.out.println("八进制 " + octal + " 转换为二进制: " + Integer.toBinaryString(decimal));System.out.println("八进制 " + octal + " 转换为十进制: " + decimal);System.out.println("八进制 " + octal + " 转换为十六进制: " + Integer.toHexString(decimal).toUpperCase());}private static void hexToOthers(String hex) {int decimal = Integer.parseUnsignedInt(hex, 16);System.out.println("十六进制 " + hex + " 转换为二进制: " + Integer.toBinaryString(decimal));System.out.println("十六进制 " + hex + " 转换为八进制: " + Integer.toOctalString(decimal));System.out.println("十六进制 " + hex + " 转换为十进制: " + decimal);}}

C#编号转换

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 编码转换
{internal class Program{static void Main(string[] args){Console.WriteLine("欢迎使用进制转换工具!");while (true){Console.WriteLine("请选择要转换的进制类型:");Console.WriteLine("1. 二进制转其他");Console.WriteLine("2. 十进制转其他");Console.WriteLine("3. 八进制转其他");Console.WriteLine("4. 十六进制转其他");Console.WriteLine("5. 退出");int choice = int.Parse(Console.ReadLine());if (choice == 5){break;}Console.WriteLine("请输入要转换的数值:");string input = Console.ReadLine();switch (choice){case 1:BinaryToOthers(input);break;case 2:DecimalToOthers(int.Parse(input));break;case 3:OctalToOthers(input);break;case 4:HexToOthers(input);break;default:Console.WriteLine("无效的选择,请重新选择!");break;}}Console.WriteLine("感谢使用本工具!");}private static void BinaryToOthers(string binary){int decimalValue = Convert.ToInt32(binary, 2);Console.WriteLine($"二进制 {binary} 转换为十进制: {decimalValue}");Console.WriteLine($"二进制 {binary} 转换为八进制: {Convert.ToString(decimalValue, 8)}");Console.WriteLine($"二进制 {binary} 转换为十六进制: {Convert.ToString(decimalValue, 16).ToUpper()}");}private static void DecimalToOthers(int decimalValue){Console.WriteLine($"十进制 {decimalValue} 转换为二进制: {Convert.ToString(decimalValue, 2)}");Console.WriteLine($"十进制 {decimalValue} 转换为八进制: {Convert.ToString(decimalValue, 8)}");Console.WriteLine($"十进制 {decimalValue} 转换为十六进制: {Convert.ToString(decimalValue, 16).ToUpper()}");}private static void OctalToOthers(string octal){int decimalValue = Convert.ToInt32(octal, 8);Console.WriteLine($"八进制 {octal} 转换为二进制: {Convert.ToString(decimalValue, 2)}");Console.WriteLine($"八进制 {octal} 转换为十进制: {decimalValue}");Console.WriteLine($"八进制 {octal} 转换为十六进制: {Convert.ToString(decimalValue, 16).ToUpper()}");}private static void HexToOthers(string hex){int decimalValue = Convert.ToInt32(hex, 16);Console.WriteLine($"十六进制 {hex} 转换为二进制: {Convert.ToString(decimalValue, 2)}");Console.WriteLine($"十六进制 {hex} 转换为八进制: {Convert.ToString(decimalValue, 8)}");Console.WriteLine($"十六进制 {hex} 转换为十进制: {decimalValue}");}}
}

关键字:中国企业排行榜_建筑公司网址_手机百度高级搜索_刚刚济南发通知

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: