a) Convert the following 2 numbers to binary, octal and hex. 2.875, 0.1796875 Wh
ID: 3603286 • Letter: A
Question
a) Convert the following 2 numbers to binary, octal and hex.
2.875, 0.1796875
When done, convert the following to a float representation
by the definition in class. In other words, I want an 8 digit hex
number representation using the 4 byte float specification
defined in class.
b) Do the same for a) given they are negative values.
c) Convert the float representations of the following into
the decimal number given the definition in class.
59999901, 59999902, A66667FE
Note: This doesn't require a program, however, I want you to write a
simple function that outputs the answers you did by hand with "cout".
Explanation / Answer
When working with any kind of digital electronics in which numbers are being represented, it is important to understand the different ways numbers are represented in these systems. Almost without fail, numbers are represented by two voltage levels which can represent a one or a zero (an interesting exception to this rule is the new memory device recently announced by Intel which uses one of four possible voltage levels, thereby increasing the amount of information that can be stored in a given space). The number system based on ones and zeroes is called the binary system (because there are only two possible digits). Before discussing the binary system, a review of the decimal (ten possible digits) system is in order, because many of the concepts of the binary system will be easier to understand when introduced alongside their decimal counterpart.
You should all have some familiarity with the decimal system. For instance, to represent the positive integer one hundred and twenty-five as a decimal number, we can write (with the postivie sign implied). The subscript 10 denotes the number as a base 10 (decimal) number.
12510 = 1*100 + 2*10 + 5*1 = 1*102 + 2*101 + 5*100
The rightmost digit is multiplied by 100, the next digit to the left is multiplied by 101, and so on. Each digit to the left has a multiplier that is 10 times the previous digit. Hopefully this is all a review. Some observations:
Representing fractions is a simple extension of this idea. To wit,
25.43 10 = 2*10 + 5*1 + 4*0.1 + 3*0.01 = 2*101 + 5*100 + 4*10-1+ 3*10-2
The only pertinent observations here are:
After reading this dcoument you might want to learn something about binary arithmetic.
Binary Representation of positive integers
Binary representations of positive can be understood in the same way as their decimal counterparts. For example
8610 = 1*64 + 0*32 + 1*16 + 0*8 + 1*4 + 1*2 + 0*1
or
8610 = 1* 26 + 0* 25 + 1* 24 + 0* 23 + 1* 22 + 1* 21 + 0* 20
or
8610 = 1010110 2
The subscript 2 denotes a binary number. Each digit in a binary number is called a bit. The number 1010110 is represented by 7 bits. Any number can be broken down this way, by finding all of the powers of 2 that add up to the number in question (in this case 26, 24, 22 and 21). You can see this is exactly analagous to the decimal deconstruction of the number 125 that was done earlier. Likewise we can make a similar set of observations:
Exercises:
Hexadecimal, Octal, Bits, Bytes and Words.
It is often convenient to handle groups of bits, rather than individually. The most common grouping is 8 bits, which forms a byte. A single byte can represent 256 (28) numbers. Memory capacity is usually referred to in bytes. Two bytes is usually called a word, or short word (though word-length depends on the application). A two-byte word is also the size that is usually used to represent integers in programming languages. A long word is usually twice as long as a word. A less common unit is the nibble which is 4 bits, or half of a byte.
It is cumbersome for humans to deal with writing, reading and remembering individual bits, because it takes many of them to represent even fairly small numbers. A number of different ways have been developed to make the handling of binary data easier for us. The most common is hexadecimal. In hexadecimal notation, 4 bits (a nibble) are represented by a single digit. There is obviously a problem with this since 4 bits gives 16 possible combinations, and there are only 10 unique decimal digits, 0 to 9. This is solved by using the first 6 letters (A..F) of the alphabet as numbers. The table shows the relationship between decimal, hexadecimal and binary.
There are some significant advantages to using hexadecimal when dealing with electronic representations of numbers (if people had 16 fingers, we wouldn't be saddled with the awkward decimal system). Using hexadecimal makes it very easy to convert back and forth from binary because each hexadecimal digit corresponds to exactly 4 bits (log 2(16) = 4) and each byte is two hexadecimal digit. In contrast, a decimal digit corresponds to log2(10) = 3.322 bits and a byte is 2.408 decimal digits. Clearly hexadecimal is better suited to the task of representing binary numbers than is decimal.
As an example, the number CA3 16 = 1100 1010 00112 (11002 = C16 , 10102 = A16, 00112 = 3 16). It is convenient to write the binary number with spaces after every fourth bit to make it easier to read. Converting back and forth to decimal is more difficult, but can be done in the same way as before.
323510 = C16*256 + A16*16 + 316*1 = C16 *162 + A16 *161 + 316 *160
or
323510 = 12*256 + 10*16 + 3*1 = 12*162 +10*161 +3*160
Octal notation is yet another compact method for writing binary numbers. There are 8 octal characters, 0...7. Obviously this can be represented by exactly 3 bits. Two octal digits can represent numbers up to 64, and three octal digits up to 512. A byte requires 2.667 octal digits. Octal used to be quiete common, it was the primary way of doing low level I/O on some old DEC computers. It is much less common today but is still used occasionally (e.g., to set read, write and execute permissions on Unix systems)
In summary:
bit
a single binary digit, either zero or one.
byte
8 bits, can represent positive numbers from 0 to 255.
hexadecimal
A representation of 4 bits by a single digit 0..9,A..F. In this way a byte can be represented by two hexadecimal digits
long word
A long word is usually twice as long as a word.
nibble
4 bits, half of a byte.
octal
A representation of 3 bits by a single digit 0..7. This is used much less commonly than it once was (early DEC computers used octal for much of their I/O)
word
Usually 16 bits, or two bytes. But a word can be almost any size, depending on the application being considered -- 32 and 64 bits are common sizes
Exercises:
Convert 125 from decimal to binary Convert 96 from decimal to binary Convert 10011 from binary to decimal In 'C', an unsigned integer is usually 16 bits. What is the largest number that can be represented by an unsigned integer? Convert 37 to binary, shift it left by one and convert back to decimal. What is the result Decimal Hexadecimal Binary 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 Convert 2000 from decimal to hexadecimal Convert 3C from hexadecimal to decimal Convert 1010 0111 1011 from binary to hexadecimal Convert 7D0 from hexadecimal to binary If you shift a hexadecimal number to the left by one digit, how many times larger is the resulting number?Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.