十进制表示:区域十进制和压缩十进制之间的用途不同 [英] Decimal Presentation : different purpose between zoned decimal and packed decimal

查看:232
本文介绍了十进制表示:区域十进制和压缩十进制之间的用途不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习计算机科学课程,当我阅读这些定义时,我就会明白.但是我不知道两个演示文稿有什么不同的目的以及为什么. 这是我的书所说的目的的简短解释:

I'm learning Computer Science course and when I read to these definition, I understand. But I don't know what different purpose of two presentations and why. Here some short explanation of purpose that my book said:

Zone decimal : hightly compatible with text data.
Packed decimal : faster computing speed.

我想知道的是:

1)在区域小数表示中,有一个区域部分重复每个数字.为什么 ?我看这没有用:(

1) in zone decimal presentation there is a zone section that duplicate every digit. Why ? I see this is no purpose :(

2)为什么他们说十进制区域与文本数据兼容,以及为什么打包的十进制数更快.

2) why they say zone decimal is compatible with text data and why packed decimaal is faster.

谢谢:)

推荐答案

首先-您在哪里学习CS?这些术语来自1960年代,更常见的名称是BCD(二进制编码的十进制)

Firstly - where are you learning CS? Those terms are from the 1960s, the more common name is BCD (Binary Coded Decimal)

十进制区域的每个数字都使用整个字节.这意味着您可以像打印文本一样直接打印一个数字(每个字符"存储一个0-9的数字),但是由于只有10个数字并且一个字节可以容纳256个不同的值,所以这有点浪费.

Zone decimal uses an entire byte for each digit. This means you can just print a number as if it was text (each 'character' stores a digit 0-9) but since there are only 10 digits and a byte can hold 256 different values this is a bit wasteful.

压缩十进制使用4位可以存储16个不同值的事实.因此,您可以在一个字节中存储两个数字(高4位和低4位).由于您仅使用一半的容量,因此这仍然有些浪费.但是,只需通过移位和掩码操作就可以提取两个数字.

Packed decimal uses the fact that 4bits can store 16different values. So you can store two digits in a byte (top 4bits and bottom 4bits). This is still a bit wasteful since you only use half the capacity. But it's pretty easy to extract the two digits with just shift and mask operations.

这些天,您几乎唯一会看到BCD的地方是一些底层硬件,您想要在不使用微处理器的情况下读/写数字.仅在晶体管中制作BCD计数器很容易

Pretty much the only place you would see BCD these days is in some low level hardware where you want to read/x-mit a digit without using a microprocessor at all. It's easy to make a BCD counter just in transistors

但是,如果您想进行任何数学运算,则必须像在纸上一样对每个数字进行长乘法-或转换为常规整数并再次返回

but if you want to do any maths you either have to do long multiplication on each digit like you would on paper - or convert into regular ints and back again

这篇关于十进制表示:区域十进制和压缩十进制之间的用途不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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