Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
This week's book giveaway is in the
Java in General
forum.
We're giving away four copies of
Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework
and have Michael Redlich on-line!
See
this thread
for details.
Win a copy of
Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework
this week in the
Java in General
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Beginning Java
cannot convert from long to byte
Nikos Stavros
Ranch Hand
Posts: 243
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
for some reason I get this error in this code, how can I fix it?
byte[]b = new byte[4]; b[0] = (aLongNumber & 0xFF000000L) >> 24;
Jesus lives
Keith Lynn
Ranch Hand
Posts: 2412
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Are you familiar with casting?
Nikos Stavros
Ranch Hand
Posts: 243
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
yes, I tried this and it worked, thanks
buf[0] = (byte)(anUnsignedInt & 0xFF000000L >> 24); buf[1] = (byte)(anUnsignedInt & 0x00FF0000L >> 16); buf[2] = (byte)(anUnsignedInt & 0x0000FF00L >> 8); buf[3] = (byte)(anUnsignedInt & 0x000000FFL);
Jesus lives
Nikos Stavros
Ranch Hand
Posts: 243
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
however I get strange results
Convert_int_into_4_bytes(312243); public void Convert_int_into_4_bytes(long anUnsignedInt){ byte[]buf = new byte[4]; buf[0] = (byte)(anUnsignedInt & 0xFF000000L >> 24); buf[1] = (byte)(anUnsignedInt & 0x00FF0000L >> 16); buf[2] = (byte)(anUnsignedInt & 0x0000FF00L >> 8); buf[3] = (byte)(anUnsignedInt & 0x000000FFL); System.out.print(buf[0] + " " + buf[1] + " " + buf[2] + " " + buf[3]);
It prints out "-77 -77 -77 -77" I can figure out why I get the same numbers
Jesus lives
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hint: The >> operator has preference above the & operator.
Jesper's Blog
-
Pluralsight Author Page
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Assignments
Bit wise ,shift Operators practical usage
Rules Roundup #305
bit shifting
A doubt in bitwise operator
More...