473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Scaling 32 bit data to 16 bits

Hi, I am trying to model a DSP system in C++ using fixed point arithmetic. At one point I've come across the need to scale down a 32 bit data to 16 bits. Does anybody have an algorithm/C++ code to do this.

Any info in this regard will be of great help. Thanks in anticpation.
Dec 30 '10 #1
7 5766
johny10151981
1,059 1GB
can you explain what do you mean by scale down?
if you want to store a 32 bit data in two 16 data field it is very much possible....

but if you want to loose data more than 16 bit it also possible.

but if you think to fit 32 bit data in 16 bit field. So far this is impossible(as far i know)
Jan 4 '11 #2
Well yes, what I am asking is if we can fit 32 bit data into a 16 bit field. The actual requirement is to compare two values; one 16 bit (say 'a') and the other 32 bit (say 'b').

It doesn't make sense to assign 'b' (32 bit) directly to a 16 bit value as the fixed point library I am using will saturate the value to 2^16 and will still be the greater of 'a' and 'b'.

So is there any way/algorithm to represent a 32 bit data in an equivalent 16 bit form without losing information.

I know this sounds crazy, but there could be some way out.
Jan 5 '11 #3
donbock
2,426 Expert 2GB
You refer to a fixed point library. What precisely are the types (and encodings) of the two variables?

"So is there any way/algorithm to represent a 32 bit data in an equivalent 16 bit form without losing information."
If such technique existed it could be used to reduce 32 bit data into 16 bits, then used again to reduce the 16 bit data into 8 bits, and used over and over again until only one bit is left.
There are certain degenerate cases where you can accomplish a semblance of this -- consider a 32-bit integer whose high-order 16 bits are all zero. In this case you have 16-bit data in a 32-bit variable, so there is no problem copying the data into a 16-bit variable.
Jan 5 '11 #4
Thanks donbock;


Yes, the library uses variables of 'fxpt' (fixed point) type whose structures and functions are defined in a .h and .cpp file respectively. The fxpt data are basically floating point numbers converted to fixed point representation using the normal fp to fxpt conversion technique. (i.e (floating pt num)*(2^N); where N is the desired number of bits representing the fractional part of floating pt num in its fxpt representation).

The degenerate case as mentioned by you is not an option in my case as the data seldom has 16 '0' higher order bits.
Jan 5 '11 #5
hype261
207 100+
Maybe I am missing something, but if your requirement is to compare at 32 bit field and a 16 bit field why can't you convert the 16 bit field into a 32 bit? That way you don't have to worry about any loss of data.
Jan 5 '11 #6
donbock
2,426 Expert 2GB
You haven't provided a precise description of the fixed point types so I can't give you a precise answer.

In general, more bits means more significant digits. Generic oversimplification follows... You convert from narrower to wider type by appending zeros to the right of the decimal point; you convert from wider to narrower type by truncating some of the right-most decimal digits.

These fixed-point types are not part of the C Standard so you can't merely cast from one to the other. Presumably your library provides interconversion functions or macros. (Unless this is one of the ways in which C++ differs from C.)
Jan 5 '11 #7
Rabbit
12,516 Expert Mod 8TB
In essence, what you are asking is, can I represent the number 327 using only 2 digits? The answer is no. But if you are asking, can I represent the number 027 using only 2 digits? Then yes.
Jan 5 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: EN | last post by:
Hi, I'm trying to send 8 bits to the lpt port. I'd like to use VB 6.0. Can this be done? VB can send data to a printer, but can it go as low as actually sending bits? I think VB can only send...
27
by: geskerrett | last post by:
I am hoping someone can help me solve a bit of a puzzle. We are working on a data file reader and extraction tool for an old MS-DOS accounting system dating back to the mid 80's. In the data...
17
by: IanIpp | last post by:
We have a 3 month old quad processor/dual core server running SQL Server 2005 and already it is getting close to hitting the CPU wall. An 8 way CPU box is prohibitively expensive and out of the...
36
by: Chuck Faranda | last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem is getting serial data back from my device. My get commands have to be sent twice for the PIC to respond properly with...
1
by: vijay punnam | last post by:
hai all, i am trying to develop a simulator ( inplace of a PIC micro controller) for my application. i need to send/receive 9 data bits along with 1 start and 1 stop bit( totally 11bits) for...
0
by: Rogoras | last post by:
I use termios.h and have following problem: My computer comunicates to host computer usig serial RS232. Host is using parity bit as wake up bit and 8 data bits. In other words parity bit is...
8
by: Ringo | last post by:
I have a micro controller that sends a stream of 102 bytes to the pc. The values range from 0 to 255. I set up my serialport like this sp.BaudRate = 115200; sp.PortName = "COM53"; sp.DataBits =...
7
by: JoeC | last post by:
I am trying to create a windows program that reads binary graphics as a resource. This has nothing to do with win32 but conversion of data with memcpy. graphic::graphic(UINT uiResID, HINSTANCE...
6
by: anu29dolly | last post by:
Hello everyone... I have written a program to write and read data from serial port.... I am able to write 80(in binary)..and is expecting 1B but i am uable to read it... My code goes as...
10
by: Dave067 | last post by:
Hi I'm a Python newbie trying to write a datalogger to acquire data from a laboratory meter using RS232. Hardware: Samsung N100 laptop. Maplin's USB-Serial converter dongle. TSI 4100 series...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.