Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7759207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:34:10+00:00 2026-06-01T13:34:10+00:00

Trying to understand the math of this code snippet. A token is provided which

  • 0

Trying to understand the math of this code snippet. A token is provided which is always 8 digits. It enters a class typed as a long. The token is being broken up into separate bytes to be sent over a stream.

long token = 85838276; 

byte cp[] = {
            1, 0, 0, 0, 0
            };

cp[4] = (byte)(int)token; // not sure what would become of token
cp[3] = (byte)(int)(token >> 8);   
cp[2] = (byte)(int)(token >> 16);  
cp[1] = (byte)(int)(token >> 24);  

I understand the typecasting (byte) part but not having (byte)(int) together. Does the token which is of type long, have to step down one simple type at a time? Couldn’t you omit the (int) and have the same result?

Is the order important or is it just written from cp[4] to cp[1] for clarity.
I realize the token in cp[4] will not be equal to the original value since the max value the byte type can hold is 127. Is it possible to recreate the original token once it has reached its destination?

Lastly I would like to recreate this in php. I know a string is already a byte stream. Each character sent would be one byte. Do I need to send a string of characters with each character being equal to integer value it represents. Such as a for 41

Updated:
So according to Louis Wasserman’s answer, when type cast to byte, only the last byte is kept.

Token  in binary: 101000111011100100111000100 // cp[4] = 11000100

Token shifted 08: 1010001110111001001 // cp[3] = 11001001

Token shifted 16: 10100011101 // cp[2] = 00011101

Token shifted 24: 101 // cp[1] = 101
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:34:11+00:00Added an answer on June 1, 2026 at 1:34 pm

    As far as I can tell, (byte) (int) is equivalent to (byte) in this context.

    That wouldn’t be true for all double casts, but it seems true here. They’re both “narrowing” cast conversions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand Ruby a bit better, I ran into this code surfing the
I'm trying to understand the math on this raphael.js demo: http://raphaeljs.com/pie.js Checkout the sector
I'm trying to understand why my code isn't working. this is a piece of
I'm currently trying to understand per pixel collision detection. This is the code I
After trying to understand why client code is not rendered in a page (injected
Trying to understand why this doesn't work. I keep getting the following errors: left
I've got part of code from friend and I'm trying to understand it and
I'm trying to convert the math presented on this paper: http://www.bouncingchairs.net/pskalman-lategecco.pdf Around page 3
I'm looking into speeding up my python code, which is all matrix math, using
I`m a newbie at JavaScript trying to understand this tutorial about currying from Oreilly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.