Original Post
🔒 Locked
Float to bits
Advertisement
Their way:
x /= 2 shifts x right by 1 ( n / 2 = n >> 1)
x % 2 gets the rightmost bit
examples:
3 = 0b11
3 % 2 = 1 (rightmost bit)
3 / 2 = 1
1 % 2 = 1 (rightmost bit)
A much easier way. (bitset constructor)
[font=verdana, arial, helvetica, sans-serif]bitset ( unsigned long val );[/font]
Having said that, what are you trying to do? Why do you need to access individual bits of a float?
x /= 2 shifts x right by 1 ( n / 2 = n >> 1)
x % 2 gets the rightmost bit
examples:
3 = 0b11
3 % 2 = 1 (rightmost bit)
3 / 2 = 1
1 % 2 = 1 (rightmost bit)
A much easier way. (bitset constructor)
[font=verdana, arial, helvetica, sans-serif]bitset ( unsigned long val );[/font]
Having said that, what are you trying to do? Why do you need to access individual bits of a float?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement