Home
Username:
Password:
Advanced C Programming Tutorials

Types of Data / Bits

Subtitles of the Movie

C has the advantage of a high-level language in its logic flow control and the way it can be used to organize your code and it also has the advantage of assembly language in the way it can manipulate bits. This lesson is about floating-point bits and how you can get to them. There is some variation in the exact format of the bits in a floating-point number. Most common is I triple E 754 and most modern floating-point formats are very similar to it. This is the layout of a 32-bit floating-point number. One bit is used for the sign bit. Positive and negative floating-point numbers are the same. This bit set to one indicates that the number is negative and zero specifies that it's positive. The eight-bit exponent is in what is known as the excess bios format. It's eight bits long so it can represent 256 values. It's nominal value is 127, which is the normal exponent value for a number one or two. But the variation of the exponent can be positive or negative to represent the decimal point being moved to the left or the right. Actually it's not a decimal point because this is a base-two number so it's actually a binary point. The 23-bits of the fraction represent the digits of the number itself. The fraction is normalized. That means it has been shifted over so it has no leading zeros. Any leading zero values are represented by adjusting the count of the exponent value. Actually it has been shifted one bit further than that. The first bit is always one so there is no need to save a place for it. With the fraction portion being 23 bits in length and the leading bit being implied, it looks like you have 24 bits of accuracy and in a way, that's true. But by the time you perform some math, the accuracy drops. Approximations build up fast. It's that creeping approximation that gives you problems if you try to using floating-point numbers for monetary calculations. There is no unsigned float. This comes from a fact that the complexity of representing floating-point numbers is large enough. Adding an unsigned float would only add one bit to the precision of the exponents and it would double the complexity of floating-point operations. Some values are special. Other than regular normalized and un-normalized values, three have been defined. If all the bits are set to zero, it is actually one times two to the modest one-hundred-twenty-seventh power. That's a very small number but it's not zero so for convenience, the fraction and exponent being zero is special. It's defined as zero for floating-point operations. By the way, there is both a positive and a negative zero. Another special definition is infinity. You could have both positive and negative infinity. Infinity results from dividing by zero. One special case is called N-A-N; not a number. This comes from performing an operation that isn't defined, like dividing zero by zero. You can look inside the floating-point values on your system. All you need do is declare a union with a floating-point number you want to analyze with an Array of unsigned eight-bit integers. You can assign a value to the floating-point number and look at the bits and the integers. This program displays the value of the floating-point numbers followed by the values of their bytes. When you get from this may not be what you expect to get. The problem comes from two places. First, the format of the floating-point numbers in your C compiler may not be the same as those I've described here. Second, the Intel chips reverse bytes so things don't show up in their real positions. To really dig into the internal formats on your computer, you'll need to experiment by storing different values in the floating-point variables of this program and see what happens.

Tutorial Information

Course: Advanced C Programming
Author: Arthur Griffith
SKU: 33965
ISBN: 1-935320-24-6
Release Date: 2009-01-30
Duration: 5.5 hrs / 82 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available