Java绘制统计图

article/2025/9/27 4:24:19

0. 前言

本文采用第三方库xchart进行绘制,所需要使用的jar包如下:

https://download.csdn.net/download/hfy1237/86508408

https://download.csdn.net/download/hfy1237/86508849

一、折线图

1. 方式一(快速绘图)

package plot;import org.knowm.xchart.QuickChart;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;public class SampleXchart {public static void main(String[] args) {// 创建数据double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };double[] yData = new double[] { 0.0, 1.2, 1.5, 2.0, 4.5, 6.8, 7.9, 11.3, 3.9, 4, 22};// 创建图表XYChart chart = QuickChart.getChart("折线图", "X", "Y", "y(x)", xData, yData);// 进行绘制new SwingWrapper<XYChart>(chart).displayChart();}}

2. 方式二

package plot;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.CategorySeries.CategorySeriesRenderStyle;
import org.knowm.xchart.SwingWrapper;public class Example {public static void main(String[] args) {// 创建数据double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };double[] yData = new double[] { 0.0, 1.2, 1.5, 2.0, 4.5, 6.8, 7.9, 11.3, 3.9, 4, 22};// 创建ChartCategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("折线图").xAxisTitle("Mean").yAxisTitle("Count").build();//设置图表样式chart.getStyler().setDefaultSeriesRenderStyle(CategorySeriesRenderStyle.Line);// 添加数据源chart.addSeries("Fake Data", xData, yData);// 进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}}

3. 方式三

package plot;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.CategorySeries.CategorySeriesRenderStyle;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.style.colors.XChartSeriesColors;
import org.knowm.xchart.style.lines.SeriesLines;
import org.knowm.xchart.style.markers.SeriesMarkers;public class Example {public static void main(String[] args) {// 创建数据double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };double[] yData = new double[] { 0.0, 1.2, 1.5, 2.0, 4.5, 6.8, 7.9, 11.3, 3.9, 4, 22};// 创建ChartXYChart chart = new XYChartBuilder().width(800).height(600).title("折线图").xAxisTitle("Mean").yAxisTitle("Count").build();// 添加数据源XYSeries series = chart.addSeries("Fake Data", xData, yData);series.setLineColor(XChartSeriesColors.BLUE);series.setMarker(SeriesMarkers.CIRCLE);series.setLineStyle(SeriesLines.SOLID);// 进行展示new SwingWrapper<XYChart>(chart).displayChart();}}

二、 条形图

1. 基本条形图

package plot;import java.util.Arrays;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.style.Styler.LegendPosition;public class SampleXchart {public static void main(String[] args) {// 创建Chart对象CategoryChart chart =new CategoryChartBuilder().width(800).height(600).title("图形标题").xAxisTitle("Score").yAxisTitle("Number").build();// 设置图例显示位置chart.getStyler().setLegendPosition(LegendPosition.InsideNE);// 设置标签是否可见chart.getStyler().setLabelsVisible(false);// 设置网格是否可见chart.getStyler().setPlotGridLinesVisible(false);// 添加绘图数据chart.addSeries("图例", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(4, 5, 9, 6, 5));// 进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}}

2. 堆积条形图

package plot;import java.util.Arrays;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.SwingWrapper;public class Example {public static void main(String[] args) {// 创建Chart对象CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("图形标题").xAxisTitle("Score").yAxisTitle("Number").build();// 设置标签是否可见chart.getStyler().setLabelsVisible(false);// 设置网格是否可见chart.getStyler().setPlotGridLinesVisible(false);// 设置是否堆积chart.getStyler().setOverlapped(true);// 添加绘图数据chart.addSeries("Bar1", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(4, 6, 5, 8, 7));chart.addSeries("Bar2", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(14, 15, 14, 18, 17));// 进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}}

3. 并列条形图

package plot;import java.util.Arrays;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.SwingWrapper;public class Example {public static void main(String[] args) {// 创建Chart对象CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("图形标题").xAxisTitle("Score").yAxisTitle("Number").build();// 设置标签是否可见chart.getStyler().setLabelsVisible(false);// 设置网格是否可见chart.getStyler().setPlotGridLinesVisible(false);// 添加绘图数据chart.addSeries("Bar1", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(4, 6, 5, 8, 7));chart.addSeries("Bar2", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(14, 15, 14, 18, 17));// 进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}}

三、直方图

1. 基本直方图

package plot;import java.util.Arrays;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.Histogram;
import org.knowm.xchart.SwingWrapper;public class Example {public static void main(String[] args) {// 创建ChartCategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("直方图").xAxisTitle("Mean").yAxisTitle("Count").build();// 添加数据源Histogram histogram = new Histogram(Arrays.asList(new Number[] { 1, 1, 3, 5, 7, 9, 10, 10, 10 }), 5, 0, 10);chart.addSeries("histogram", histogram.getxAxisData(), histogram.getyAxisData());// 进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}}

2. 堆积直方图

 

package plot;import java.util.ArrayList;
import java.util.List;
import java.util.Random;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.Histogram;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.style.Styler.LegendPosition;public class Example {public static void main(String[] args) {// 创建ChartCategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build();// 自定义Chartchart.getStyler().setLegendPosition(LegendPosition.InsideNW);chart.getStyler().setAvailableSpaceFill(.5); // 设置有效填充区域占比chart.getStyler().setOverlapped(true);// 添加数据源Histogram histogram1 = new Histogram(getGaussianData(10000), 20, -20, 20);Histogram histogram2 = new Histogram(getGaussianData(5000), 20, -20, 20);chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData());chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData());// 显示图表new SwingWrapper<CategoryChart>(chart).displayChart();}private static List<Double> getGaussianData(int count) {List<Double> data = new ArrayList<Double>(count);Random r = new Random();for (int i = 0; i < count; i++) {data.add(r.nextGaussian() * 10);}return data;}
}

3. 并列直方图

package plot;import java.util.ArrayList;
import java.util.List;
import java.util.Random;import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.Histogram;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.Styler.LegendPosition;public class Example {public static void main(String[] args) {// 创建Chart对象CategoryChart chart =new CategoryChartBuilder().width(800).height(600).title("并列直方图").xAxisTitle("Mean").yAxisTitle("Count").build();// 自定义图表对象chart.getStyler().setLegendPosition(LegendPosition.InsideNW);chart.getStyler().setAvailableSpaceFill(.96);chart.getStyler().setPlotGridVerticalLinesVisible(false);chart.getStyler().setToolTipsEnabled(true);chart.getStyler().setToolTipType(Styler.ToolTipType.yLabels);// 添加数据源Histogram histogram1 = new Histogram(getGaussianData(1000), 10, -30, 30);chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData());Histogram histogram2 = new Histogram(getGaussianData(1000), 10, -30, 30);chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData());//进行展示new SwingWrapper<CategoryChart>(chart).displayChart();}private static List<Integer> getGaussianData(int count) {List<Integer> data = new ArrayList<Integer>(count);Random r = new Random();for (int i = 0; i < count; i++) {data.add((int) (r.nextGaussian() * 10));}return data;}}

四、散点图 

package plot;import java.util.LinkedList;
import java.util.List;
import java.util.Random;import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries.XYSeriesRenderStyle;
import org.knowm.xchart.style.Styler.LegendPosition;public class SampleXchart {public static void main(String[] args) {// Create ChartXYChart chart = new XYChartBuilder().width(800).height(600).build();// 设置图表样式chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter);chart.getStyler().setChartTitleVisible(false);chart.getStyler().setLegendPosition(LegendPosition.InsideSW);chart.getStyler().setMarkerSize(16);// 添加数据List<Double> xData = new LinkedList<Double>();List<Double> yData = new LinkedList<Double>();Random random = new Random();int size = 1000;for (int i = 0; i < size; i++) {xData.add(random.nextGaussian() / 1000);yData.add(random.nextGaussian());}chart.addSeries("Gaussian Blob", xData, yData);// 展示图表new SwingWrapper<XYChart>(chart).displayChart();}
}

五、饼状图

package plot;import java.awt.Color;import org.knowm.xchart.PieChart;
import org.knowm.xchart.PieChartBuilder;
import org.knowm.xchart.SwingWrapper;public class BarChart01 {public static void main(String[] args) {PieChart chart = new PieChartBuilder().width(800).height(600).title("饼状图演示").build();// 创建ChartColor[] sliceColors = new Color[] { new Color(224, 68, 14), new Color(230, 105, 62), new Color(236, 143, 110), new Color(243, 180, 159), new Color(246, 199, 182) };chart.getStyler().setSeriesColors(sliceColors);// 添加数据源chart.addSeries("Gold", 24);chart.addSeries("Silver", 21);chart.addSeries("Platinum", 39);chart.addSeries("Copper", 17);chart.addSeries("Zinc", 40);// 进行展示new SwingWrapper<PieChart>(chart).displayChart();}}

六、绘制多幅图表

package plot;import java.util.ArrayList;
import java.util.List;import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.style.markers.SeriesMarkers;public class Example {public static void main(String[] args) {int numCharts = 4;List<XYChart> charts = new ArrayList<XYChart>();for (int i = 0; i < numCharts; i++) {XYChart chart = new XYChartBuilder().xAxisTitle("X").yAxisTitle("Y").width(600).height(400).build();chart.getStyler().setYAxisMin(-10.0); // 设置y轴的最小值chart.getStyler().setYAxisMax(10.0);  // 设置y轴的最大值// 添加数据源XYSeries series = chart.addSeries("" + i, null, getRandomWalk(200));// 不显示标记series.setMarker(SeriesMarkers.NONE);charts.add(chart);}// 显示图表new SwingWrapper<XYChart>(charts).displayChartMatrix();}/*** 产生随机游走数据** @param numPoints* @return*/private static double[] getRandomWalk(int numPoints) {double[] y = new double[numPoints];y[0] = 0;for (int i = 1; i < y.length; i++) {y[i] = y[i - 1] + Math.random() - .5;}return y;}}

七、自定义图表

1. 基本自定义选项

package plot;import java.awt.Color;
import java.awt.Font;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.style.Styler.LegendPosition;
import org.knowm.xchart.style.colors.XChartSeriesColors;
import org.knowm.xchart.style.lines.SeriesLines;
import org.knowm.xchart.style.markers.SeriesMarkers;public class Example {public static void main(String[] args) {// 创建Chart对象XYChart chart = new XYChartBuilder().width(800).height(600).title("图表属性演示").xAxisTitle("X").yAxisTitle("Y").build();//=====================自定义图表对象=====================// 设置图表背景色chart.getStyler().setPlotBackgroundColor(Color.white);// 设置图表网格线是否可见chart.getStyler().setPlotGridLinesVisible(true);// 设置图表网格线颜色chart.getStyler().setPlotGridLinesColor(Color.black);// 设置图形背景色chart.getStyler().setChartBackgroundColor(Color.gray);// 设置图例背景色chart.getStyler().setLegendBackgroundColor(Color.red);// 设置图形字体颜色chart.getStyler().setChartFontColor(Color.orange);// 设置图形标题方框背景色chart.getStyler().setChartTitleBoxBackgroundColor(Color.green);// 设置图形标题方框是否可见chart.getStyler().setChartTitleBoxVisible(true);// 设置图形标题方框边缘颜色chart.getStyler().setChartTitleBoxBorderColor(new Color(210, 2, 0));// 设置坐标轴刻度与图表的距离chart.getStyler().setAxisTickPadding(10);chart.getStyler().setAxisTickMarkLength(10);// 设置绘图边框chart.getStyler().setPlotMargin(10);// 设置图表标题字体chart.getStyler().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24));// 设置图例字体chart.getStyler().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));// 设置图例位置chart.getStyler().setLegendPosition(LegendPosition.InsideSE);// 设置图例线条长度chart.getStyler().setLegendSeriesLineLength(20);// 设置坐标轴字体chart.getStyler().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));// 设置坐标轴刻度字体chart.getStyler().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11));// 设置日期样式chart.getStyler().setDatePattern("dd-MMM");// 设置十进制样式chart.getStyler().setDecimalPattern("#0.000");// 设置区域chart.getStyler().setLocale(Locale.GERMAN);// 生成数据List<Date> xData = new ArrayList<Date>();List<Double> yData = new ArrayList<Double>();DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");Date date = null;for (int i = 1; i <= 10; i++) {try {date = sdf.parse(i + ".10.2008");} catch (ParseException e) {e.printStackTrace();}xData.add(date);yData.add(Math.random() * i);}// 设置数据样式XYSeries series = chart.addSeries("Fake Data", xData, yData);series.setLineColor(XChartSeriesColors.BLUE);series.setMarkerColor(Color.ORANGE);series.setMarker(SeriesMarkers.CIRCLE);series.setLineStyle(SeriesLines.SOLID);// 显示图表new SwingWrapper<XYChart>(chart).displayChart();}
}

2. Matlab风格

package plot;import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.style.Styler.ChartTheme;
import org.knowm.xchart.style.markers.SeriesMarkers;public class Example {public static void main(String[] args) {// 创建ChartXYChart chart = new XYChartBuilder().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build();// 添加数据源chart.getStyler().setPlotGridLinesVisible(false);chart.getStyler().setXAxisTickMarkSpacingHint(100);// SeriesList<Integer> xData = new ArrayList<Integer>();for (int i = 0; i < 640; i++) {xData.add(i);}List<Double> y1Data = getYAxis(xData, 320, 160);List<Double> y2Data = getYAxis(xData, 320, 320);List<Double> y3Data = new ArrayList<Double>(xData.size());for (int i = 0; i < 640; i++) {y3Data.add(y1Data.get(i) - y2Data.get(i));}XYSeries series = chart.addSeries("Gaussian 1", xData, y1Data);series.setMarker(SeriesMarkers.NONE);series = chart.addSeries("Gaussian 2", xData, y2Data);series.setMarker(SeriesMarkers.NONE);series = chart.addSeries("Difference", xData, y3Data);series.setMarker(SeriesMarkers.NONE);// 进行展示new SwingWrapper<XYChart>(chart).displayChart();}private static List<Double> getYAxis(List<Integer> xData, double mean, double std) {List<Double> yData = new ArrayList<Double>(xData.size());for (int i = 0; i < xData.size(); i++) {yData.add((1 / (std * Math.sqrt(2 * Math.PI)))* Math.exp(-(((xData.get(i) - mean) * (xData.get(i) - mean)) / ((2 * std * std)))));}return yData;}}

八、保存图片到本地

BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.PNG);
BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.JPG);
BitmapEncoder.saveJPGWithQuality(chart, "./Sample_Chart_With_Quality.jpg", 0.95f);
BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.BMP);
BitmapEncoder.saveBitmap(chart, "./Sample_Chart", BitmapFormat.GIF);BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.PNG, 300);
BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.JPG, 300);
BitmapEncoder.saveBitmapWithDPI(chart, "./Sample_Chart_300_DPI", BitmapFormat.GIF, 300);VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.EPS);
VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.PDF);
VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.SVG);


http://chatgpt.dhexx.cn/article/h2aO7bjj.shtml

相关文章

mysql 中文本类型有哪些_mysql数据类型有哪些

mysql数据类型有:1、数值类型;2、日期和时间类型;3、字符串类型是CHAR、VARCHAR、BINARY【二进制数据类型】、BLOB、TEXT【文本类型】、ENUM【枚举类型】和SET【数据集合】。 mysql数据类型有: MySQL支持的数据类型在几类:数值类型,日期和时间类型和字符串(字符)类型。 数…

mysql polygon 类型_MySQL数据类型 - 空间数据类型 (4)

支持的空间数据格式 有两种标准空间数据格式用于表示查询中的几何对象: ●已知文本(WKT)格式 ●已知二进制(WKB)格式 在内部,MySQL用与WKT或WKB格式不同的格式存储几何值。(内部格式类似于WKB,但有一个4个字节表示SRID。) MySQL提供函数可用于在不同的数据格式之间进行转换。…

MySQL数据类型-整数类型

MySQL提供了多种数据类型&#xff0c;包括整数类型、浮点数类型、定点数类型、日期和时间类型、字符串类型、二进制数据类型&#xff1b; 不同的数据类型有各自的的类型&#xff0c;使用范围也各不相同&#xff0c;而且存储方式也不相同 有两种类型的数字&#xff1a;整数和实…

MySQL 数据类型及占用空间

MySQL 数据类型 元数据 VARCHAR类型字符串及DECIMAL的占用空间实际上包含2部分&#xff0c;一是存储数据本身占用的空间&#xff0c;二是描述数据的元数据占用的空间&#xff0c;例如VARCHAR类型会使用1个字节记录存入数据实际的字符数。 最大行大小限制 MySQL表的内部表示…

Mysql数据类型与选择规则(mysql5.7)

概述 基于mysql5.7。 mysql数据类型大致可以分为四类&#xff1a;数值型、字符串型、日期和时间类型、空间类型。常用的如数值型的tinyint、int、bigint,字符串型的char、varchar、text&#xff0c;日期型的date、datetime、timestemp等&#xff0c;详细见下图&#xff1a; …

Mysql数据类型详解

1、整数类型&#xff0c;包括TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT&#xff0c;分别表示1字节、2字节、3字节、4字节、8字节整数。 任何整数类型都可以加上UNSIGNED属性&#xff0c;表示数据是无符号的&#xff0c;即非负整数。 长度&#xff1a;整数类型可以被指定长度…

mysql成绩是什么数据类型_mysql数据类型

1、整型 取值范围如果加了unsigned&#xff0c;则最大值翻倍&#xff0c;如tinyint unsigned的取值范围为(0~256)。 int(m)里的m是表示SELECT查询结果集中的显示宽度&#xff0c;并不影响实际的取值范围&#xff0c;没有影响到显示的宽度&#xff0c;不知道这个m有什么用。 2、…

最全MySQL数据类型详解

一、概述 1、MySQL中的数据类型 2、常见数据类型的属性 二、各种数据类型精讲 1、整数类型 1.1 整数类型介绍 整数类型一共有 5 种&#xff0c;包括 TINYINT、SMALLINT、MEDIUMINT、INT&#xff08;INTEGER&#xff09;和 BIGINT。它们的区别如下表所示&#xff1a; 1.2…

mysql住址数据类型_MySql数据类型

MySQL中定义数据字段的类型对你数据库的优化是非常重要的。 MySQL支持多种类型&#xff0c;大致可以分为三类&#xff1a;数值、日期/时间和字符串(字符)类型。 数值类型 MySQL支持所有标准SQL数值数据类型。 这些类型包括严格数值数据类型(INTEGER、SMALLINT、DECIMAL和NUMERI…

不全?MySQL数据类型精讲,定点日期枚举文本字符串,json二进制,空间,选择建议,完整详细可收藏

文章目录 1. MySQL中的数据类型2. 整数类型3. 浮点数类型4. 定点数类型5. 位类型&#xff1a;BIT6. 日期与时间类型7. 文本字符串类型8. ENUM类型9. SET类型10. 二进制字符串类型11. JSON 类型12. 空间类型13. 选择建议 1. MySQL中的数据类型 常见数据类型的属性&#xff0c;如…

MySQL的10种常用数据类型

MySQL的数据类型 常用的数据类型有&#xff1a; 整型&#xff08;xxxint&#xff09;位类型(bit)浮点型&#xff08;float和double、real&#xff09;定点数&#xff08;decimal,numeric&#xff09;日期时间类型&#xff08;date,time,datetime,year&#xff09;字符串&…

定点数除法

定点数除法 一&#xff0c;手工除法运算方法二&#xff0c;原码除法运算方法三&#xff0c;原码加/减交替除法运算方法&#xff08;不恢复余数法&#xff09;四&#xff0c;原码加/减交替除法实现逻辑五&#xff0c;阵列除法 一&#xff0c;手工除法运算方法 图 1 图1 图1 二&…

浮点数与定点数理解、定点数转浮点数相互转换

1、浮点数理解 在平常的代码编写中大家经常用到float 32、double 64等&#xff0c;但是否有深入的去了解一下这类数据是怎么表示的呢&#xff1f;今天我们就去学习浮点数的表示方法&#xff0c;以及其优缺点。 首先浮点数为什么叫浮点数呢&#xff1f;因为浮点数的小数点的位…

定点数的几种表示形式

第二章 数制与编码 2.1 进制之间的转换 掌握&#xff1a;二进制、八进制、十六进制(末位加H表示)、十进制及彼此之间的转换&#xff1b; 问&#xff1a;小数怎么转换&#xff1f; 十进制转二进制&#xff1a;乘以权值再累加&#xff0c;如小数点后第一位的权值是2^(-1) 二进…

计算机中定点数表示方法练习

1【单选题】针对8位二进制数,下列说法中正确的是 。&#xff08;5.0分&#xff09; A、-127的补码为10000000 B、-127的反码等于0的移码 C、1的移码等于-127的反码 D、0的补码等于-1的反码 正确答案&#xff1a; B 2【单选题】若某数x的真值为-0.1010,在计算机中该数表示为1.0…

定点数的表示和运算

本文主要介绍以下几方面知识&#xff1a; 定点数的表示&#xff08;无符号数、有符号数&#xff09;移位运算&#xff08;原码、反码、补码&#xff09;加减运算&#xff08;原码加减、补码加减&#xff09;乘法运算&#xff08;原码乘法、补码乘法&#xff09;除法运算&#x…

进制以及浮点数和定点数

文章目录 一&#xff0c;进制&#xff08;1&#xff09;全国各地最熟悉也最习惯的进制--十进制数1.十进制2.基数3.十进制数的权位展开式4.十进制权位展开式的理解5.十进制对于计算机的局限 &#xff08;2&#xff09;计算机所能理解的进制--二进制数1.二进制2.数据存储3.常见信…

定点数的乘除运算

定点数的乘除运算 定点数的乘法运算原码一位乘法手算模拟补码一位乘法&#xff08;Booth算法&#xff09; 定点数的除法法运算原码除法运算恢复余数法不恢复余数法 补码除法运算&#xff08;加减交替法&#xff09;总结 定点数的乘法运算 在计算机中&#xff0c;乘法运算由累加…

定点数的加减法

文章目录 1.补码加法1.1 补码加法公式1.2 补码加法公式证明 2.补码减法3.溢出概念与检测方法3.1 溢出的概念3.2 溢出的检测方法 参考文献 数值运算的核心是指加、减、乘、除四则算术。由于计算机中的数有定点和浮点两种表示形式&#xff0c;因此相应有定点数的运算和浮点数的运…

定点数类型

正因为用浮点数表示小数可能会有不精确的情况&#xff0c;在一些情况下我们必须保证小数是精确的&#xff0c;所以设计MySQL的大叔们提出一种称之为定点数的数据类型&#xff0c;它也是存储小数的一种方式&#xff1a; 其中&#xff1a; M表示该小数最多需要的十进制有效数字个…