473,385 Members | 2,004 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,385 software developers and data experts.

splitting 'unsigned long long int'(uint64_t) to 8 bytes(int8_t).

Hi,
I'm writing an application that receives data(ASCII characters) serially via wiegand interface into a variable uint64_t mydata. I need to split mydata into 8 bytes which represents individual characters.

Can somebody help me with a way to split/convert uint64_t into 8 bytes.

Thanks you in advance.
Feb 2 '10 #1
3 6560
weaknessforcats
9,208 Expert Mod 8TB
Can't you just typecast a pointer to this uint64_t to a unsigned char?

That way you could use the uint_64_t as an unsigned char array[8].
Feb 2 '10 #2
Banfa
9,065 Expert Mod 8TB
While that method works on many many platforms (well all the diffeent ones I have used) the standard does not guaranttee that the conversion of any pointer to any other pointer except for pointer to type to pointer to void or casting up and down a class heiarchy is valid.

Therefore casting like that is not strictly portable although it is very likely to work.

A portable (but slower) method would be to use the bitwise operators (<< >> &) to isolate each individual byte in the 64 bit value.
Feb 2 '10 #3
donbock
2,426 Expert 2GB
Also, using the bitwise shift makes your code endian-neutral.
Feb 2 '10 #4

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

Similar topics

24
by: Matt Feinstein | last post by:
Hi all-- I'm new to Python, and was somewhat taken aback to discover that the core language lacks some basic numerical types (e.g., single-precision float, short integers). I realize that there...
14
by: David Fisher | last post by:
The most common sizes of integer types seem to be: 8 bits - signed char 16 bits - short 16 or 32 bits - int 32 or 64 bits - long Question #1: Does anyone know how common sizes other than...
8
by: Shailesh | last post by:
One problem I've been wrestling with for a long time is how to use the C++ integral data types, vis-a-vis their size. The C++ rules guarantee that a char is at least 1 bytes, a short and int at...
8
by: phil-news-nospam | last post by:
I have some code where I am using certain literal values cast to stdint types like uint32_t, uint64_t, etc. In gcc versions below 3.3 it's working OK. Here's an example: (uint64_t)...
8
by: Bryan Parkoff | last post by:
int has two bytes or four bytes. long has four bytes or eight bytes. I can't be sure to choose int or long keyword because I don't trust to get the wrong size. I always check by using...
20
by: Frederick Gotham | last post by:
Here's an excerpt from the Dinkumware library reference: __________ | uint8_t, uint16_t, uint32_t, uint64_t | | The types each specify an unsigned integer type | whose representation has exactly...
0
by: Gordon Schumacher | last post by:
I found a clever way to solve this issue: I used a variant of the code at http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64171. On one hand, this code is fairly arcane, and I realize that...
166
by: Nimmi Srivastav | last post by:
Apologies if my cross posting has offended anyone.... For a pure hobbyist C/C++ programmer, who wants to develop applications to run on Windows, what would be a better choice to install: Visual...
5
by: pereges | last post by:
I wrote a small program to check the range for int(signed) and long int(signed) on my machine: #include <stdio.h> #include <limits.h> int main(void) { printf("INT_MIN:%d INT_MAX: %d",...
6
by: Chris Forone | last post by:
hello group, is the cast of int8_t and uint8_t in char for streaming in both directions (put(), get()) defined/plattform independent? i have read here in the forum, that int8_t and uint8_t are...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.