Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1788857
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: 其他平台

2013-07-28 00:11:48

We tend to come across COMP, COMP-3 etc. very frequently in mainframes. Some facts:

  • Did you know that COMP-3 means Packed Decimal format? 
  • Did you know that BINARY, COMP and COMP-4 mean the same? 
  • In COMP-3 format, one byte will store 2 decimal digits (and the rightmost byte will have one digit and the sign). If we use a COMP-3 for even number of digits then we'll waste half a byte on the leftside. So generally all COMP-3s will be declared to store an odd number of digits. 
  • COMP-3 values are not readable (will appear with junk values) when the file is opened in normal mode. 
  • Why not use a normal picture clause (like 9(4) which are called DISPLAY format)? DISPLAY formats use one byte for every decimal digit. DISPLAY formats can be directly viewed when you open the file. 
  • Why not use binary format instead of packed decimal? It's easier to convert from packed decimal into display than from binary to display.

Food for thought: Why is it that when we view a file in HEX mode, comp-3 formats are readable?


KR-56 : More COBOL COMPs!

What's a COMP/ Binary format?

  • COMP, COMP-4 and BINARY refer to the same format. They are well-suited for arithmetic operations since the numbers are stored in binary format. Wondering what's binary format? 
  • Let's take the decimal number 48.

    In COMP-3 (packed decimal) format, the 2 digits will be considered separately. i.e. the number 4 and the number 8. And in COMP-3, two digits occupy 1 byte (or in other words; each decimal digit occupies half a byte - 4 bits). So, just convert 4 and 8 into their respective binary representations and you'll have:
    0100 1000 (for 4 and 8 respectively)
  • In COMP (or binary) format, the number 48 is stored in memory by converting 48 into its equivalent binary form. Do a decimal to binary conversion and you'll get: 
    00110000

    That's the basic difference (which leads to other differences) between a COMP and a COMP-3.

    We'll end this edition here and before we finish a Food for thought: Why does a COMP-3 appear as junk in normal view mode but is interpretable when the file is in HEX ON mode?

KR-57 : HEX Format

  • Everything in a PC is finally stored in binary format 1s and 0s by the system. These 1s and 0s are grouped together, converted using some conversion formula/table and presented to us so that we can make sense of the 1s and 0s. 
  • In PCs, the ASCII code is used for converting from characters into bytes. In mainframes (being an IBM product), the EBCDIC code is used for the same purpose. 
  • Thus when we open a flat file, the bytes are converted into characters using EBCDIC code. 

What's HEX format? HEX or hexadecimal format is similar to the decimal system except that each position can represent a maximum value of 15 (in decimal it's 0 to 9; in hexa it's 0 - F; F equals decimal 15). And to convert a decimal number to hexaformat is pretty similar to what we saw for decimal to COMP-3 conversion (and each hexa digit occupies 4 bits/half a byte); 
Or in other words, let's say we have a file with the byte: 0001 0010
When we open this file in HEX mode (just type HEX ON on the command line); the screen would show: 12 (1 in hexa is 0001 and 2 in hexa is 0010).

Well, now you should know the reason why a comp-3 is viewable in HEX ON mode; if you aren't clear; then take a small decimal number; convert it into comp-3; and then you'll be clear.
REF:
KR

阅读(1858) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~