Create an integer from a series of bits - Marching Cubes

I’m trying out a Marching Cubes algorithm as described in the [Nvidia GPU Gems][1]:

However, I’m hitting a wall with my knowledge of working directly with bits, and concating them into a workable byte of information.

As the diagram shows, each corner is represented by the algorithm as being a 1 or a 0 based on a predefined density function. 1 means the corner lies within the volume, and 0 means it is outside the volume.

My problem, though, is that I’m unclear on how exactly I should go about converting the bit information into a usable uint8. Do I store the 8-digit bit string as an FString, a TCHAR, or an array of some sort that I can convert to an int?

Any and all help will be greatly appreciated :slight_smile:

you could do whatever is convenient later on (or both for instance one for speed and one to write as text into a file)

for instance a TCHAR is 8 bit so if the values(v0…v7) are 0 or 1

TCHAR value = ((1 << 7) * v7) + ((1<<6) * v6) + …

but a string could work too:

FString str = FString( (v7) ? “1” : “0” ) + FString( (v6) ? “1” : “0” ) + …

I done this before, trying to implement marching cubes, This can be done by getting your grid points, and if the value is =>0, then add 1, like so
(GridPoints are your voxels in the cube)

Byte Caseindex = 0

If GridPoint[0] => 0 Then Caseindex =+ 1
If GridPoint[1] => 0 Then Caseindex =+ 2
If GridPoint[2] => 0 Then Caseindex =+ 4
If GridPoint[3] => 0 Then Caseindex =+ 8
If GridPoint[4] => 0 Then Caseindex =+ 16
If GridPoint[5] => 0 Then Caseindex =+ 32
If GridPoint[6] => 0 Then Caseindex =+ 64
If GridPoint[7] => 0 Then Caseindex =+ 128

Return(CaseIndex)

This works for me