Docsity

Decimal and Binary Number Systems: Interconversions - Assignment | CPSC 3121, Study notes of Programming Languages

Toggle sidebar
bg1
Decimal number 55
a) Convert this to binary.
55 div 2 = 27 rem 1
27 div 2 = 13 rem 1
13 div 2 = 6 rem 1
6 div 2 = 3 rem 0
3 div 2 = 1 rem 1
1 div 2 = 0 rem 1 110111 0011 0111
b) Convert this to hexadecimal
0011 in binary is hexadecimal 3
0111 in binary is hexadecimal 7 0x37
Also 55 = 48 + 7 = 316 + 7 = 0x37
c) Show this number as a zoned decimal.
The EBCDIC code for the character ‘5’ is F5.
The EBCDIC representation for the string “55”
is F5 F5. The zone for each is the hexadecimal F.
For a positive number replace the last zone by ‘C’
F5 C5.
d) Show this number as a packed decimal.
First, make this an odd number of digits: 055
All positive numbers end in the hexadecimal digit C,
so the value is 05 5C.
e) What is the decimal value of the hexadecimal 05 5C?
5162 + 516 + 12 = 5256 + 516 + 12 = 1372.
pf3
pf4

Partial preview of the text

Download Decimal and Binary Number Systems: Interconversions - Assignment | CPSC 3121 and more Study notes Programming Languages in PDF only on Docsity!

Decimal number 55 a) Convert this to binary. 55 div 2 = 27 rem 1 27 div 2 = 13 rem 1 13 div 2 = 6 rem 1 6 div 2 = 3 rem 0 3 div 2 = 1 rem 1 1 div 2 = 0 rem 1 110111 0011 0111 b) Convert this to hexadecimal 0011 in binary is hexadecimal 3 0111 in binary is hexadecimal 7 0x Also 55 = 48 + 7 = 316 + 7 = 0x c) Show this number as a zoned decimal. The EBCDIC code for the character ‘5’ is F5. The EBCDIC representation for the string “55” is F5 F5. The zone for each is the hexadecimal F. For a positive number replace the last zone by ‘C’ F5 C5. d) Show this number as a packed decimal. First, make this an odd number of digits: 055 All positive numbers end in the hexadecimal digit C, so the value is 05 5C. e) What is the decimal value of the hexadecimal 05 5C? 5  16 2

  • 516 + 12 = 5256 + 516 + 12 = 1372.

Decimal number 173.25. a) Convert this to binary. Whole number part: convert 173 to binary. 173 / 2 = 86 1 86 / 2 = 43 0 43 / 2 = 21 1 21 / 2 = 10 1 10 / 2 = 5 0 5 / 2 = 2 1 2 / 2 = 1 0 1 / 2 = 0 1 1010 1101 Convert the decimal part to binary. .25  2 = 0. .50  2 = 1. .00  2 = 0.00. Note that .01 in binary stands for 0/2 + 1/4 = 1/4. b) Convert to hexadecimal Start with the binary. 1010 1101. Pad with trailing zeroes 1010 1101. Convert: A D. 4 Straight conversion: 173 = 1016 + 13 173 / 16 = 10 rem 13. But 13 is less than 16. Decimal 10 is 0xA Decimal 13 is 0xD AD 0.2516 = 4

Convert the number 0.71875 to binary.

  • 0.71875  2= 1.4375
  • 0.4375  2 = 0.875
  • 0.875  2 = 1.75
  • 0.75  2 = 1.50
  • 0.50  2 = 1.00
  • 0.00  2 = 0.00
  • Read top to bottom: 0.
  • Convert to hexadecimal 0.1011 1000, or 0.B
  • This is 11/16 + 8/256 = 11/16 + 1/
    • = 22/32 + 1/
    • = 23 /
  • 1/2 + 0/4 + 1/8 + 1/16 + 1/ Also: binary .101110 represents
  • 16/32 + 4/32 + 2/32 + 1/32 = 23 /