?
Solved

get specific byte from unsigned long long

Posted on 2003-02-21
2
Medium Priority
?
180 Views
Last Modified: 2010-05-18
I have an unsigned long long k (64 bits / 8 bytes).
If we number the bytes in k 0 - 7, with byte 0 being on the rightmost end of k, does anyone know of a way to get a specific byte out? For example, byte 3?
Thanks.
0
Comment
Question by:CalTree
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
Exceter earned 200 total points
ID: 7997696
Try this,

union t
{
    unsigned long long l;
    unsigned char s[8];
};

...

union t trans;
trans.l = 12000;
printf("%2x",trans.s[0]); // Print out the first byte of l in hexadecimal

Exceter
0
 
LVL 8

Expert Comment

by:Exceter
ID: 7997709
>> 0 being on the rightmost end of k,

Ah,

printf("%2x",trans.s[7-0]); // First byte moving right to left
printf("%2x",trans.s[7-1]); // Second byte
printf("%2x",trans.s[7-2]); // Third byte

etc...

Exceter
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question