# binary - Hi Folks Here is a hint for the binary conversion...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 Hi Folks, Here is a hint for the binary conversion code: 1) Many of you will try using a variable like, INTEGER (kind=8) :: base2 to store the base-2 equivalent (all 0's and 1's) of a base-10 number in. That does not work, because the computer treats the variable "base2" as if it were a base 10 number, so you can't save enough 0's and 1's to get -10^18 to 10^18. For example, the number 4 in base-2, 100, would be interpreted as the number one hundred by the computer (not one zero zero). 2) Instead, define an array that uses word length as it's size: INTEGER :: bit(0:63) This bit array corresponds to an 8-byte word length. In this array, the base-2 equivelant of 4 would be stored as bit(0) = 0 bit(1) = 0 bit(2) = 1 bit(3) = 0 . . . bit(63)= 0 which calculates out as, bit(0)x2^0 + bit(1)x2^1 + bit(2)x2^2 = 4 or base10 = 0. DO i = 0, 63, 1 base10 = base10 + REAL(bit(i)*2**i) END DO Good luck!! Dana

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

binary - Hi Folks Here is a hint for the binary conversion...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online