The S/370 architecture provides several ways to represent numbers: Floating Point This section covers the most fundamental numeric representation, Binary Integers. A more formal presentation of some of this material is provided at the beginning of POPs Chapter 7, General Instructions, as well as some information on the other numeric representations. Further information on Packed Decimal numbers appears at the beginning of POPs Chapter 8, Decimal Instructions. The Floating Point numbers are likewise described at the beginning of POPs Chapter 9, Floating-Point Instructions.
## Binary, Decimal, Octal, and Hexadecimal## Binary, Decimal, Octal, and HexadecimalThese formats (Binary, Octal, Decimal, and Hexadecimal) are really just names for a particular instance of the mathematical concept called "base". Please do not confuse the mathematical "base" concept with the S/370 "base register" concept. Here, when we mention the word "base", we will be referring to the mathematical concept. Let's begin by defining our terms, in a less than rigorous mathematical way. If you want rigorous mathematics, you're in the wrong tutorial.
A
You can think of Binary as being "based on" the number 2, Octal as being "based on" the number 8, Decimal as being "based on" the number 10, and Hexadecimal as being "based on" the number 16. The following table shows the relationship between Name, Base, and Digits.
To represent numeric values larger than the Base, additional digits (in the range constrained by the base) will appear to the left of prior digits. In the following examples, leading zeros appear to help visually align the numbers; they serve no other purpose. In Binary, we count: 0000, 0001, In Octal, we count: 00, 01, 02, 03, 04, 05, 06, 07, In Decimal, we count: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, In Hexadecimal, we count: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0A, 0B, 0C, 0D, 0E, 0F Let's point out some interesting things about these numbers. First, notice how many places it takes to represent a Binary number as opposed to a Hexadecimal number. Next, notice how the numbers in each base range from zero to (base number minus one). Finally, notice that when we get to the base number that we add a new digit on the left, just as you are used to when counting in decimal. The numbers zero through 255 appear in various formats (Decimal, Hexadecimal, and Binary) in the Code Translation Table of the S/370 Reference Summary (REFSUM). ## Powers of TwoExperienced assembler programmers usually recognize the following binary, decimal and hexadecimal equivalents because the "one" bit is just shifted over one (binary) place. In the binary column, a space is introduced to aid pattern recognition.
Two comments about the above table. First, when you want to use a byte of main storage to contain a set of flags, the above values (stated in hexadecimal, decimal, or binary as you prefer) are the values of each flag bit. Second, this table is also a table of Powers of Two, such as appears in the REFSUM. Our table gives the first eight Powers of Two, which are missing from the REFSUM. The REFSUM didn't bother to include the first eight Powers of Two because they are so commonly known, and they were short on space. In case you don't deal with raising numbers to a power every day, by definition any number raised to the zeroth power equals one. ## Powers of Sixteen
## Bits, Nibbles, and BytesIn the S/370 architecture, each Binary digit occupies one bit in main memory. Each Hexadecimal digit can be viewed as though it were composed of four Binary digits. These four bits are sometimes called a "nibble". Two Hexadecimal digits occupies a byte (8 bits). This grouping of four Binary digits, or one Hexadecimal digit, is actually a pun: a nibble is half a byte. ## S/370 Assembler Notation
Although subscripts are normally used to indicate the base of
a number, such as 197 To solve the problem, the S/370 assembler introduces some notational conventions which it recognizes in lieu of subscripts. There are a wealth of such notations, but we will only cover two here: one notation for Binary, and one notation for Hexadecimal. Binary numbers are framed with B'xxxx'. The Binary number 1001 is thus represented by B'1001'. Hexadecimal numbers are framed with X'xxxx'. The Hexadecimal number 2D4F is thus represented by X'2D4F'. Some of you might know the C language, and the same number would be represented by 0x2D4F in C source code; the S/370 Assembler won't understand the 0x notation. Leading zeros are not required for either Binary of Hexadecimal numbers. ## Converting Numbers## Converting Hexadecimal to DecimalGiven a hexadecimal number X'52EC', convert it to decimal. The first technique we show here is summarized in the REFSUM in the "Hexadecimal and Decimal Conversion" section. There are four nibbles in the number X'52EC'. Use each of these nibbles to index into the "Hexadecimal Columns" matching the nibble's place. The same technique, when viewed mathematically is: 52EC |