-
I did some research, and only c++ has unions and single-bit data structures. Now, through the demonic ingenuity of my thought processes, i recalled how i did the bit access.
Code:
union char_bin_hex { //edit: changed struct to union
char ch;
union char_to_bin bits;
union char_to_hex dibits;
}
struct char_to_bin { //edit: changed union to struct
unsigned b1: 1
unsigned b2: 1
unsigned b3: 1
unsigned b4: 1
unsigned b5: 1
unsigned b6: 1
unsigned b7: 1
unsigned b8: 1
}
struct char_to_hex { //edit: changed union to struct
unsigned d1: 2
unsigned d2: 2
unsigned d3: 2
unsigned d4: 2
}
All you do is put the char into char_bin_hex.ch and access the individual bits/dibits through char_bin_hex.bits.b1 etc and char_bin_hex.dibits.d1 etc.
Hope this helps! I will work on a function tht works with this when iget back frm church & lunch.
~Inquirer
-
Quote:
Originally posted by Inquirer
I did some research, and only c++ has unions and single-bit data structures. Now, through the demonic ingenuity of my thought processes, i recalled how i did the bit access.
Code:
struct char_bin_hex {
char ch;
union char_to_bin bits;
union char_to_hex dibits;
}
union char_to_bin {
unsigned b1: 1
unsigned b2: 1
unsigned b3: 1
unsigned b4: 1
unsigned b5: 1
unsigned b6: 1
unsigned b7: 1
unsigned b8: 1
}
union char_to_hex {
unsigned d1: 2
unsigned d2: 2
unsigned d3: 2
unsigned d4: 2
}
All you do is put the char into char_bin_hex.ch and access the individual bits/dibits through char_bin_hex.bits.b1 etc and char_bin_hex.dibits.d1 etc.
Hope this helps! I will work on a function tht works with this when iget back frm church & lunch.
~Inquirer
Is it just me or did you get that a little backwards? The unions should be structures, and the structure should be a union. Or else i'm an idiot. (Then again i've never done anything like that before)
-
OOPS!
Yeah! You're right!
I am editing that now, so don't get confused by eibro's post guys...
Now i can actually make the function correctly!
-
/split
::: see my new thread :::