Docsity

Storing Binary Data - Lecture Notes | CPSC 3121, Study notes of Programming Languages

Toggle sidebar
bg1
Storing Data (Binary)
Problem 1.
Given the decimal number 29, what is it hexadecimal equivalent?
Answer: In decimal, 29 = 16 + 13. Decimal 13 = 0xD. Then, we have Answer: 1D.
Problem 2:
This value is stored in a location declared as
H1 DC Hโ€˜0โ€™ The value here is initialized to 0, but can be overwritten.
What is the value stored, in hexadecimal?
Answer:
How many bytes are assigned to H1? Two
What are the hexadecimal values stored? Xโ€˜001Dโ€™
NOTE: One hexadecimal digit represents 4 bits. 0x0 is 0000 and 0xF = 1111.
One byte represents eight bits. It can be represented as 2 hexadecimal digits.
A halfword is 16 bits. It can be represented by four hexadecimal digits.*
A fullword is 32 bits. It can be represented by eight hexadecimal digits.*
*This is IBM mainframe terminology.
pf3
pf4

Partial preview of the text

Download Storing Binary Data - Lecture Notes | CPSC 3121 and more Study notes Programming Languages in PDF only on Docsity!

Storing Data (Binary)

Problem 1. Given the decimal number 29, what is it hexadecimal equivalent? Answer: In decimal, 29 = 16 + 13. Decimal 13 = 0xD. Then, we have Answer: 1D. Problem 2: This value is stored in a location declared as H1 DC Hโ€˜0โ€™ The value here is initialized to 0, but can be overwritten. What is the value stored, in hexadecimal? Answer: How many bytes are assigned to H1? Two What are the hexadecimal values stored? Xโ€˜001Dโ€™ NOTE: One hexadecimal digit represents 4 bits. 0x0 is 0000 and 0xF = 1111. One byte represents eight bits. It can be represented as 2 hexadecimal digits. A halfword is 16 bits. It can be represented by four hexadecimal digits.* A fullword is 32 bits. It can be represented by eight hexadecimal digits.* *This is IBM mainframe terminology.

Packed Decimal Look at the declaration P1 DC PL4โ€˜123456โ€™ What is the value stored, in hexadecimal digits? Xโ€˜0123456Cโ€™. P2 DC PL3 โ€˜12โ€™ How many bytes of data here? 3 bytes. What is the value stored (in hex) X โ€˜00012Cโ€™ P3 DC PL4โ€˜14โ€™ Decimal value 14 How many bytes of data? 4 What is the value in hex? Xโ€˜0000014Cโ€™ How does this look in binary? 0000 0000 0000 0000 0000 0001 0100 1100 Open Question We execute the instruction LH 3,P What value, in decimal, is stored in register 3? Reason: The halfword beginning at address P3 is 0000 0000 0000 0000

Name DC Cโ€˜ABโ€™ What is the hexadecimal value stored? Xโ€˜C1C2โ€™ One strange question. Zero DC Pโ€˜0โ€™ What is the value in hexadecimal stored at zero? X โ€˜0Cโ€™ This one byte is loaded into a register. What decimal value is loaded? 12 Another strange question. Take the declaration Z1 DC Pโ€˜0โ€™ One byte Xโ€˜0Cโ€™ Z2 DC Pโ€˜1โ€™ One byte Xโ€˜1Cโ€™ We execute the instruction LH 7,Z1. What hexadecimal value is loaded into register 7? Xโ€˜0C1Cโ€™