[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey, /wsr/. I'm working on an assingment for my CS class,

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 5
Thread images: 1

File: bastard-code.png (43KB, 591x1500px) Image search: [Google]
bastard-code.png
43KB, 591x1500px
Hey, /wsr/. I'm working on an assingment for my CS class, and I've hit a snag on it. I'm supposed to use bitshifting for an Arduino to find different base values for a given dec number. I found the bin fine, and I found a crude way to find hex values, but I can't get negative values correct for octal conversion which tells me that my ghetto rigged hex code is also wrong somewhere.

Not sure if /wsr/ has a code option like /g/ does, so I've just screencapped the part of the assignment that I'm needing
>>
>>375783
They way you are probably meant to do this is not by converting dec->hex / dec->oct directly but by going dec->bin->hex and dec->bin->oct. Since Hex is just 4bytes and octal 3 bytes you can easily convert it to from binary.
Anyway that how I did it for a completely different course and language.
>>
>>375797
bits not bytes sorry.
>>
>>375797
That is what we're supposed to do, but I can't figure out a code to take the certain number of bits at a time even with googling since most places will just tell you to use the built in oct/hex functions. Arduino is essentially C++, so if you have any knowledge of that, it would help
>>
Just copy the input in a temporary variable and use repeated modulo and division by the base.

For powers of two you can replace this by masking the bits and shifting, respectlively.

Problem: You get the digits in reverse order (from right to left), but since you are storing the string instead of directly outputting this should be no problem.

>negative numbers
It depends if you need to display the stored bits or a mathematically correct number.
So -5 = -101 in base 2, but it's usually stored differently (e.g. 1...11111011 as two's complement).
Thread posts: 5
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.