Android Question Display a single byte on the screen using images for 1's and 0's

tman

Member
Licensed User
Longtime User
My program returns a single byte.
I would like to display this byte on the screen as a binary number using images instead of 1's and 0's
So, instead of showing 1's and 0's it would display image1 for bit1 and image0 for bit 0
Only 2 images are used - image0 and image1 to represent a "0" bit or "1" bit
For example: Byte = 0A hex or (10 Dec)
in Binary this is 000010010
on the screen I want to display 8 images (one for each bit)
image0 - image0 - image0 - image0 - image1 -image0 - image0 - image1 - image0
Any ideas how to code this?
 

tman

Member
Licensed User
Longtime User
Assuming you get the "number" on a variable named MyByte:
B4X:
ImageView1.SetBackgroundImage(LoadBitmap(File.DirAssets, "image" & MyByte & ".jpg"))
How do I take the varible "mybyte" and return each individual bit to examine?
In other words how do I look at each individual bit contained in a byte?

Here is the general idea:

I need a way to determine is the first bit is a 1 or 0 then
if 1st bit = "0" then loadbitmap image0.jpg
if 1st bit = "1" then loadbitmap image1.jpg

Then examine the 2nd bit
if 2nd bit = "0" then loadbitmap image0.jpg
if 2nt bit = "1" then loadbitmap image1.jpg

Otherwise, I may take your advise and create 256 background images and swap them out depending on the "MyByte" variable.

-Thank you
 
Last edited:
Upvote 0
Top