473,386 Members | 1,823 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,386 software developers and data experts.

Convert bytes data from const void *data to double

1
i received bytes data from some other function to myfunction(const void *data) where pointer data stores the values like {0,0,0,0,0,0,0,40,20,0,0,0,0,0,0}.
I created an array data1 to store the values {40,20,0,0,0,0,0,0} from the above values considering endianess issue i also reversed data1 and used memcpy to copy data1 but having problem when i call myfunction then it has argument data not data1. So anyone know how can i call data1 by calling myfunction.
I want to access just values from {40,20,0,0,0,0,0,0} and convert into a double type value that should give 8.0 .
Jul 31 '14 #1
2 2332
weaknessforcats
9,208 Expert Mod 8TB
The custom inn passing an array to a function is to also pass the number of elements.

If you write in C++, then you use a template for the type to avoid the void*.

If you write in C, then you also have to pass a third argument to represent the type so the function knows how to cast the void* to the correct type. Like, maybe, if the third argument is 1 then the functions casts from void* to int* but if it's 2, then the function casts from void* to double*.
Jul 31 '14 #2
donbock
2,426 Expert 2GB
Are you absolutely certain that the program sending the byte stream and the program receiving the byte stream happen to use the same encoding format for double? If you have any doubt at all, then you should specify some particular format for the byte stream and then carefully encode the byte stream in the sending program and decode the byte stream in the receiving program.

Merely casting the byte stream to a double is not reliable in the general case.

A convenient portable format for floating point data is decimal ASCII (that is, 8.0 is encoded by "8.0\n". The necessary encoding and decoding functions are part of the Standard Library.
Aug 1 '14 #3

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

Similar topics

14
by: Enrico `Trippo' Porreca | last post by:
Given: typedef struct Node Node; struct Node { void *obj; Node *next; }; typedef struct Stack Stack; struct Stack {
16
by: Peter Ammon | last post by:
Often times, I'll have some malloc()'d data in a struct that need not change throughout the lifetime of the instance of the struct. Therefore, the field within the struct is declared a pointer to...
17
by: codeslinger | last post by:
What is the point of the construct in the subject line? Why the use of two const labels? Does that do something different than const void *x? And what would void * const x indicate? Thanks in...
6
by: bob_jenkins | last post by:
{ const void *p; (void)memset((void *)p, ' ', (size_t)10); } Should this call to memset() be legal? Memset is of type void *memset(void *, unsigned char, size_t) Also, (void *) is the...
4
by: vivekian | last post by:
Hi, This is the part of the code am trying to compile to : void Server::respondToClient ( std::string response ) { .... .... if ((numbytes = sendto ( sockFd_ , response , sizeof(response)...
3
by: bg_ie | last post by:
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen,...
2
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with:...
28
by: lovecreatesbeauty | last post by:
Is the keyword const necessary in the comparison function in qsort and bsearch? int (*compar)(const void *, const void *) If the pointer cannot be dereferenced why worry if the pointed object...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: Happy2006 | last post by:
Hello I am trying to call a function in C from C# though c ++ so basically C# -> C++ - >C In C#, I have byte bytes - which reads the information from the file. I am passing the byte array...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.